home · contact · privacy
First scripts for Bullseye.
[config] / bullseye / setup_scripts / init_user_login.sh
1 #!/bin/sh
2 # This script assumes a server with key-based root access into one of
3 # key-based access only to a new non-root account plom.
4 #
5 # CAUTION: This is optimized for a *fresh* setup. It will overwrite any
6 # old /etc/ssh/sshd_config.
7 #
8 # Dependencies: ssh, scp, properly configured sshd_config file in reach.
9 set -e
10
11 # Location of an sshd_config with "PermitRootLogin no" and
12 # "PasswordAuthentication no".
13 config_tree_prefix="${HOME}/public_repos/config/bullseye"
14 linkable_files_dir="${config_tree_prefix}/etc_files/server"
15 system_path_sshd_config='/etc/ssh/sshd_config'
16 local_path_sshd_config="${linkable_files_dir}${system_path_sshd_config}"
17
18 # Ensure we have a server name as argument.
19 if [ $# -eq 0 ]; then
20     echo "Need server as argument."
21     false
22 fi
23 server="$1"
24
25 # So we're only asked once …
26 eval $(ssh-agent)
27 ssh-add
28
29 # This will be used to log-in as root from plom account.
30 echo 'Asking for new root password.'
31 ssh root@"${server}" "passwd"
32
33 # Set up plom's ~/.ssh/authorized_keys from root's.
34 ssh root@"${server}" 'useradd -m plom'
35 ssh root@"${server}" 'mkdir /home/plom/.ssh'
36 ssh root@"${server}" 'chown plom:plom /home/plom/.ssh'
37 ssh root@"${server}" 'cp /root/.ssh/authorized_keys /home/plom/.ssh/'
38 ssh root@"${server}" 'chown plom:plom /home/plom/.ssh/authorized_keys'
39
40 # Set up SSH config and remove direct SSH login to root.
41 scp "${local_path_sshd_config}" root@"${server}":"${system_path_sshd_config}"
42 ssh root@"${server}" 'rm -rf /root/.ssh && service ssh restart'