File tree 3 files changed +42
-2
lines changed
3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 29
29
addUserAccount " ${username} " " ${password} "
30
30
31
31
read -rp $' Paste in the public SSH key for the new user:\n ' sshKey
32
- addSSHKey " ${username} " " ${sshKey} "
32
+ addSSHKey " ${username} " " ${sshKey} "
33
+ changeSSHConfig
34
+ setupUfw
35
+
36
+ sudo service ssh restart
Original file line number Diff line number Diff line change @@ -29,4 +29,14 @@ function execAsUser() {
29
29
local exec_command=${2}
30
30
31
31
sudo -u " ${username} " -H sh -c " ${exec_command} "
32
+ }
33
+
34
+ function changeSSHConfig() {
35
+ sudo sed -re ' s/^(\#?)(PasswordAuthentication)([[:space:]]+)yes/\2\3no/' -i.$( echo ' old' ) /etc/ssh/sshd_config
36
+ sudo sed -re ' s/^(\#?)(PermitRootLogin)([[:space:]]+)(.*)/PermitRootLogin no/' -i /etc/ssh/sshd_config
37
+ }
38
+
39
+ function setupUfw() {
40
+ sudo ufw allow OpenSSH
41
+ yes y | sudo ufw enable
32
42
}
Original file line number Diff line number Diff line change @@ -40,10 +40,31 @@ function testAddingOfSSHKey() {
40
40
assertEquals " ${ssh_file} " " ${dummy_key} "
41
41
}
42
42
43
+ function testChangeSSHConfig() {
44
+ changeSSHConfig
45
+
46
+ local ssh_config=" $( sudo cat /etc/ssh/sshd_config) "
47
+ assertContains " PasswordAuthentication no" " ${ssh_config} "
48
+ assertContains " PermitRootLogin no" " ${ssh_config} "
49
+ }
50
+
51
+ function testUfw() {
52
+ setupUfw
53
+
54
+ local ufw_status=$( sudo ufw status)
55
+ assertContains " Status: active" " ${ufw_status} "
56
+ assertContains " OpenSSH" " ${ufw_status} "
57
+ }
58
+
43
59
function testTeardown () {
44
60
echo " Test Teardown"
61
+
45
62
deleteTestUser
46
63
revertSudoers
64
+ revertSSHConfig
65
+
66
+ sudo ufw delete allow OpenSSH
67
+ sudo ufw disable
47
68
}
48
69
49
70
# ## Helper Functions ###
@@ -55,12 +76,17 @@ function deleteTestUser() {
55
76
56
77
function revertSudoers() {
57
78
sudo cp /etc/sudoers.bak /etc/sudoers
58
- sudo rm -rf sudoers.bak
79
+ sudo rm -rf /etc/ sudoers.bak
59
80
}
60
81
61
82
function disableSudoPassword() {
62
83
sudo cp /etc/sudoers /etc/sudoers.bak
63
84
sudo bash -c " echo '${test_user_account} ALL=(ALL) NOPASSWD: ALL' | (EDITOR='tee -a' visudo)"
64
85
}
65
86
87
+ function revertSSHConfig() {
88
+ sudo cp /etc/ssh/sshd_config.old /etc/ssh/sshd_config
89
+ sudo rm -rf /etc/ssh/sshd_config.old
90
+ }
91
+
66
92
runUnitTests
You can’t perform that action at this time.
0 commit comments