home · contact · privacy
08598ce8e39ce0504c668f9f40100ef75486e73c
[config] / buster / setup_scripts / init_user_login.sh
1 #!/bin/sh
2 set -e
3
4 # Location auf a sshd_config with "PermitRootLogin no" and
5 # "PasswordAuthentication no".
6 config_tree_prefix="${HOME}/public_repos/config/buster"
7 linkable_files_dir="${config_tree_prefix}/etc_files/server"
8 system_path_sshd_config='/etc/ssh/sshd_config'
9 local_path_sshd_config="${linkable_files_dir}${system_path_sshd_config}"
10
11 # Ensure we have a server name as argument.
12 if [ $# -eq 0 ]; then
13     echo "Need server as argument."
14     false
15 fi
16 server="$1"
17
18 # So we're only asked once …
19 eval $(ssh-agent)
20 ssh-add
21
22 # This will be used to log-in as root from plom account.
23 echo 'Asking for root password.'
24 ssh root@"${server}" "passwd"
25
26 # Set up plom's ~/.ssh/authorized_keys from root's.
27 ssh root@"${server}" 'useradd -m plom'
28 ssh root@"${server}" 'mkdir /home/plom/.ssh'
29 ssh root@"${server}" 'chown plom:plom /home/plom/.ssh'
30 ssh root@"${server}" 'cp /root/.ssh/authorized_keys /home/plom/.ssh/'
31 ssh root@"${server}" 'chown plom:plom /home/plom/.ssh/authorized_keys'
32
33 # Set up SSH config and remove direct SSH login to root.
34 scp "${local_path_sshd_config}" root@"${server}":"${system_path_sshd_config}"
35 ssh root@"${server}" 'rm -rf /root/.ssh && service ssh restart'