Manage ssh auth_key for BackupPC's user

This commit is contained in:
Jeremy Gardais 2019-05-07 11:26:19 +02:00
parent 134c18ff04
commit d8e87ee1bc
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 18 additions and 0 deletions

View File

@ -18,6 +18,7 @@ ERROR=1
backuppc_user="backuppc"
backuppc_homedir="/var/lib/backuppc"
backuppc_sshkey="from=\"129.20.203.16\" ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIhMc8ixQXfWDACJy4q0v8T877UxahhCjO51PQFzylwVpf88LX3yWeDrWIW0NRu0zoSm396mig918OpD5ggqML/QbYbQsoDdAFUV/tK4JU6UJgEQIl25MOcUBCFepsFBGS09CH/V07xSUqSP/+beeTRLNO2CQzk3S2y3YfkXpM7KmOGfeLgoCaQAcxIkgLXeM3TpCZEzJDlZ8c8k/DjVvsgwCpQktYzNo2b37KHLLfgyW9KSo6N9sReUuNQjS6lu8rjrXfc6+J0pY2D6IxWptTWL/JVrhFCUqe4QQy+xYjoR41wqnAQyl/kOcyBNhSvojMKwQT6vlPwru6pOno16/X backuppc@backuppc.ipr.univ-rennes1.fr"
## Couleur {{{
BLACK='\033[49;30m'
@ -46,6 +47,22 @@ function addUserForBackuppc() ## {{{
chown -R -- "${userLogin}:" "${userHomedir}"
}
## }}}
function manageSshKeyForBackuppc() ## {{{
{
local userLogin="${1}" ### eg. 'backuppc'
local backuppcSshKey="${2}" ### eg. 'AAAAA...
local userHomedir
userHomedir="$(getent passwd "${userLogin}" | cut -d: -f6)"
### Create ssh directory for BackupPC's user
mkdir -p -- "${userHomedir}/.ssh"
chmod 0700 -- "${userHomedir}/.ssh"
printf '%b' "${backuppcSshKey}" > "${userHomedir}/.ssh/authorized_keys"
chmod 0600 -- "${userHomedir}/.ssh/authorized_keys"
chown -R -- "${userLogin}:" "${userHomedir}"
}
## }}}
function ensureSshdIsInstalled() ## {{{
{
### `command -v sshd` still return old value even after openssh-server was removed
@ -85,6 +102,7 @@ if [ "$?" != "${SUCCESS}" ]; then
printf '%b' "${REDB}La création de l'utilisateur ${backuppc_user} a échouée, installation annulée.${RESET}\\n"
exit "${ERROR}"
fi
manageSshKeyForBackuppc "${backuppc_user}" "${backuppc_sshkey}"
# }}}
# Gestion de SSH {{{