-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_tools_ssh
executable file
·49 lines (42 loc) · 1.51 KB
/
s_tools_ssh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
#
# Bin is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Bin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Bin. If not, see <https://www.gnu.org/licenses/>.
#
# Debug Options
set -euo pipefail
# REGISTER USER
EMAIL="[email protected]"
SSH_HOME="$HOME/.ssh"
SSH_KEY="$SSH_HOME/id_ed25519"
# GENERATE NEW KEY
[[ ! -f $SSH_KEY ]] && ssh-keygen -t ed25519 -C "$EMAIL"
if [[ ! -f "$SSH_HOME/config" ]]; then
cat <<EOF >>"$SSH_HOME/config"
Host *
AddKeysToAgent yes
IdentityFile $SSH_KEY
EOF
fi
[[ -f $SSH_HOME ]] && chmod 700 "$SSH_HOME"
[[ -f $SSH_HOME/authorized_keys ]] && chmod 600 "$SSH_HOME/authorized_keys"
[[ -f $SSH_HOME/config ]] && chmod 600 "$SSH_HOME/config"
[[ -f $SSH_KEY ]] && chmod 600 "$SSH_KEY"
[[ -f $SSH_KEY.pub ]] && chmod 644 "$SSH_KEY.pub"
[[ -f $SSH_HOME/known_hosts ]] && chmod 600 "$SSH_HOME/known_hosts"
exit
# NEW GLOBAL DEFAULTS
sudo sed -i "s/Port 22|Port 33/g" # new port
sudo sed -i "PermitRootLogin no" # Disable root
sudo sed -i "AllowUsers username" # limit users acess
sudo sed -i "Protocol 2" # use protocol 2