From: Christian Heller Date: Thu, 23 Jan 2020 09:00:25 +0000 (+0100) Subject: Add server login setup for already key-based servers. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/day?a=commitdiff_plain;h=c9f396608b3369d2eb6c1c20a2a958299e84adb9;p=config Add server login setup for already key-based servers. --- diff --git a/buster/setup_scripts/init_user_login.sh b/buster/setup_scripts/init_user_login.sh new file mode 100755 index 0000000..6abb766 --- /dev/null +++ b/buster/setup_scripts/init_user_login.sh @@ -0,0 +1,31 @@ +#!/bin/sh +set -e + +# Location auf a sshd_config with "PermitRootLogin no" and +# "PasswordAuthentication no". +config_tree_prefix="${HOME}/public_repos/config/buster" +linkable_files_dir="${config_tree_prefix}/etc_files/server" +system_path_sshd_config='/etc/ssh/sshd_config' +local_path_sshd_config="${linkable_files_dir}${system_path_sshd_config}" + +# Ensure we have a server name as argument. +if [ $# -eq 0 ]; then + echo "Need server as argument." + false +fi +server="$1" + +# This will be used to log-in as root from plom account. +echo 'Asking for root password.' +ssh root@"${server}" "passwd" + +# Set up plom's ~/.ssh/authorized_keys from root's. +ssh root@"${server}" 'useradd -m plom' +ssh root@"${server}" 'mkdir /home/plom/.ssh' +ssh root@"${server}" 'chown plom:plom /home/plom/.ssh' +ssh root@"${server}" 'cp /root/.ssh/authorized_keys /home/plom/.ssh/' +ssh root@"${server}" 'chown plom:plom /home/plom/.ssh/authorized_keys' + +# Set up SSH config and remove direct SSH login to root. +scp "${local_path_sshd_config}" root@"${server}":"${system_path_sshd_config}" +ssh root@"${server}" 'rm -rf /root/.ssh && service ssh restart'