-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangeconfigssh.sh
More file actions
63 lines (50 loc) · 1.69 KB
/
changeconfigssh.sh
File metadata and controls
63 lines (50 loc) · 1.69 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# Run:
# chmod +x changeconfigssh.sh
# ./changeconfigssh.sh
set -e #Exit immediately if a comman returns a non-zero status
echo "Run: changeconfigssh.sh"
echo "Changing settings in /etc/ssh/sshd_config"
#After creating a user:
#/etc/ssh/sshd_config
#PubkeyAuthentication yes
#ChallengeResponseAuthentication yes
#AuthenticationMethods publickey password
filename="/etc/ssh/sshd_config"
#run
sudo sed -ri "s|^#?PubkeyAuthentication\s+.*|PubkeyAuthentication yes|" $filename
sudo sed -ri "s|^#?ChallengeResponseAuthentication\s+.*|ChallengeResponseAuthentication yes|" $filename
sudo sed -ri "s|^#?AuthenticationMethods\s+.*|AuthenticationMethods publickey password|" $filename
#add
if sudo grep -Fxq "PubkeyAuthentication yes" $filename
then
echo "String exists: PubkeyAuthentication yes"
else
#newline
sudo sh -c "echo '\n' >> $filename"
echo "Adding a line: PubkeyAuthentication yes"
sudo sh -c "echo 'PubkeyAuthentication yes' >> $filename"
fi
if grep -Fxq "ChallengeResponseAuthentication yes" $filename
then
echo "String exists: ChallengeResponseAuthentication yes"
else
#newline
sudo sh -c "echo '\n' >> $filename"
echo "Adding a line: ChallengeResponseAuthentication yes"
sudo sh -c "echo 'ChallengeResponseAuthentication yes' >> $filename"
fi
if grep -Fxq "AuthenticationMethods publickey password" $filename
then
echo "String exists: AuthenticationMethods publickey password"
else
#newline
sudo sh -c "echo '\n' >> $filename"
echo "Adding a line: AuthenticationMethods publickey password"
sudo sh -c "echo 'AuthenticationMethods publickey password' >> $filename"
fi
#reload
echo "Reload ssh"
sudo systemctl reload ssh
sudo systemctl status ssh
echo "Successfully"