mirror of
https://github.com/darksaid98/ubuntu-server-setup.git
synced 2026-12-01 22:22:31 +00:00
Added functionality to add ssh key
This commit is contained in:
1 parent
003357b848
commit
841312963c
5 files changed
+46
-22
No files matched your search
+21
-2
@@ -2,12 +2,31 @@
|
||||
|
||||
function addUserAccount() {
|
||||
local username=${1}
|
||||
local password=${2}
|
||||
local silent_mode=${3}
|
||||
|
||||
if [ ${2} == "true" ]; then
|
||||
if [[ ${silent_mode} == "true" ]]; then
|
||||
sudo adduser --disabled-password --gecos '' ${username}
|
||||
else
|
||||
sudo adduser ${username}
|
||||
sudo adduser --disabled-password ${username}
|
||||
echo "${username}:${password}" | sudo chpasswd
|
||||
fi
|
||||
|
||||
sudo usermod -aG sudo ${username}
|
||||
}
|
||||
|
||||
function addSSHKey() {
|
||||
local username=${1}
|
||||
local sshKey=${2}
|
||||
|
||||
execAsUser "${username}" "mkdir -p ~/.ssh; chmod 700 ~/.ssh; touch ~/.ssh/authorized_keys"
|
||||
execAsUser "${username}" "echo \"${sshKey}\" | sudo tee -a ~/.ssh/authorized_keys"
|
||||
execAsUser "${username}" "chmod 600 ~/.ssh/authorized_keys"
|
||||
}
|
||||
|
||||
function execAsUser() {
|
||||
local username=${1}
|
||||
local exec_command=${2}
|
||||
|
||||
sudo -u "${username}" -H sh -c "${exec_command}"
|
||||
}
|
||||
Reference in new issue
Block a user