mirror of
https://github.com/darksaid98/ubuntu-server-setup.git
synced 2026-12-03 22:21:31 +00:00
Added sshd_config modifications
This commit is contained in:
1 parent
2779c7f3ee
commit
9ef673594e
3 files changed
+41
-1
No files matched your search
@@ -30,3 +30,7 @@ addUserAccount "${username}" "${password}"
|
|||||||
|
|
||||||
read -rp $'Paste in the public SSH key for the new user:\n' sshKey
|
read -rp $'Paste in the public SSH key for the new user:\n' sshKey
|
||||||
addSSHKey "${username}" "${sshKey}"
|
addSSHKey "${username}" "${sshKey}"
|
||||||
|
changeSSHConfig
|
||||||
|
setupUfw
|
||||||
|
|
||||||
|
sudo service ssh restart
|
||||||
@@ -30,3 +30,13 @@ function execAsUser() {
|
|||||||
|
|
||||||
sudo -u "${username}" -H sh -c "${exec_command}"
|
sudo -u "${username}" -H sh -c "${exec_command}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeSSHConfig() {
|
||||||
|
sudo sed -re 's/^(\#?)(PasswordAuthentication)([[:space:]]+)yes/\2\3no/' -i.$(echo 'old') /etc/ssh/sshd_config
|
||||||
|
sudo sed -re 's/^(\#?)(PermitRootLogin)([[:space:]]+)(.*)/PermitRootLogin no/' -i /etc/ssh/sshd_config
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupUfw() {
|
||||||
|
sudo ufw allow OpenSSH
|
||||||
|
yes y | sudo ufw enable
|
||||||
|
}
|
||||||
+27
-1
@@ -40,10 +40,31 @@ function testAddingOfSSHKey() {
|
|||||||
assertEquals "${ssh_file}" "${dummy_key}"
|
assertEquals "${ssh_file}" "${dummy_key}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testChangeSSHConfig() {
|
||||||
|
changeSSHConfig
|
||||||
|
|
||||||
|
local ssh_config="$(sudo cat /etc/ssh/sshd_config)"
|
||||||
|
assertContains "PasswordAuthentication no" "${ssh_config}"
|
||||||
|
assertContains "PermitRootLogin no" "${ssh_config}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function testUfw() {
|
||||||
|
setupUfw
|
||||||
|
|
||||||
|
local ufw_status=$(sudo ufw status)
|
||||||
|
assertContains "Status: active" "${ufw_status}"
|
||||||
|
assertContains "OpenSSH" "${ufw_status}"
|
||||||
|
}
|
||||||
|
|
||||||
function testTeardown () {
|
function testTeardown () {
|
||||||
echo "Test Teardown"
|
echo "Test Teardown"
|
||||||
|
|
||||||
deleteTestUser
|
deleteTestUser
|
||||||
revertSudoers
|
revertSudoers
|
||||||
|
revertSSHConfig
|
||||||
|
|
||||||
|
sudo ufw delete allow OpenSSH
|
||||||
|
sudo ufw disable
|
||||||
}
|
}
|
||||||
|
|
||||||
### Helper Functions ###
|
### Helper Functions ###
|
||||||
@@ -55,7 +76,7 @@ function deleteTestUser() {
|
|||||||
|
|
||||||
function revertSudoers() {
|
function revertSudoers() {
|
||||||
sudo cp /etc/sudoers.bak /etc/sudoers
|
sudo cp /etc/sudoers.bak /etc/sudoers
|
||||||
sudo rm -rf sudoers.bak
|
sudo rm -rf /etc/sudoers.bak
|
||||||
}
|
}
|
||||||
|
|
||||||
function disableSudoPassword() {
|
function disableSudoPassword() {
|
||||||
@@ -63,4 +84,9 @@ function disableSudoPassword() {
|
|||||||
sudo bash -c "echo '${test_user_account} ALL=(ALL) NOPASSWD: ALL' | (EDITOR='tee -a' visudo)"
|
sudo bash -c "echo '${test_user_account} ALL=(ALL) NOPASSWD: ALL' | (EDITOR='tee -a' visudo)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function revertSSHConfig() {
|
||||||
|
sudo cp /etc/ssh/sshd_config.old /etc/ssh/sshd_config
|
||||||
|
sudo rm -rf /etc/ssh/sshd_config.old
|
||||||
|
}
|
||||||
|
|
||||||
runUnitTests
|
runUnitTests
|
||||||
Reference in new issue
Block a user