Richard Felkl | d59c565 | 2018-02-08 13:14:05 +0100 | [diff] [blame] | 1 | #!/bin/bash -xe |
Ivan Berezovskiy | 41a6b82 | 2018-09-11 18:02:29 +0400 | [diff] [blame] | 2 | |
| 3 | ROOT_AUTOLOGIN="" |
| 4 | if [ "$(hostname)" != "ubuntu" ]; then |
| 5 | # Auto login root on tty1 |
| 6 | sed 's|/sbin/agetty|/sbin/agetty --autologin root|g' /etc/systemd/system/getty.target.wants/getty@tty1.service > /etc/systemd/system/getty-autologin@.service |
| 7 | systemctl daemon-reload |
| 8 | systemctl disable getty@tty1.service |
| 9 | systemctl enable getty-autologin@tty1.service |
| 10 | ROOT_AUTOLOGIN="--autologin root" |
| 11 | fi |
Richard Felkl | d59c565 | 2018-02-08 13:14:05 +0100 | [diff] [blame] | 12 | |
| 13 | # Libvirt serial console support |
Ivan Berezovskiy | 41a6b82 | 2018-09-11 18:02:29 +0400 | [diff] [blame] | 14 | cat << EOF >> /etc/systemd/system/serial-getty@.service |
Richard Felkl | d59c565 | 2018-02-08 13:14:05 +0100 | [diff] [blame] | 15 | [Unit] |
| 16 | Description=Getty on %I |
| 17 | Documentation=man:agetty(8) man:systemd-getty-generator(8) |
| 18 | Documentation=http://0pointer.de/blog/projects/serial-console.html |
| 19 | After=systemd-user-sessions.service plymouth-quit-wait.service |
| 20 | After=rc-local.service |
| 21 | |
| 22 | Before=getty.target |
| 23 | IgnoreOnIsolate=yes |
| 24 | |
| 25 | ConditionPathExists=/dev/ttyS0 |
| 26 | |
| 27 | [Service] |
Ivan Berezovskiy | 41a6b82 | 2018-09-11 18:02:29 +0400 | [diff] [blame] | 28 | ExecStart=-/sbin/agetty ${ROOT_AUTOLOGIN} -8 --noclear %I 115200 \$TERM |
Richard Felkl | d59c565 | 2018-02-08 13:14:05 +0100 | [diff] [blame] | 29 | Type=idle |
| 30 | Restart=always |
| 31 | RestartSec=0 |
| 32 | UtmpIdentifier=%I |
| 33 | TTYPath=/dev/%I |
| 34 | TTYReset=yes |
| 35 | TTYVHangup=yes |
| 36 | TTYVTDisallocate=yes |
| 37 | KillMode=process |
| 38 | IgnoreSIGPIPE=no |
| 39 | SendSIGHUP=yes |
| 40 | |
| 41 | Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION= |
| 42 | |
| 43 | [Install] |
| 44 | WantedBy=getty.target |
| 45 | DefaultInstance=ttyS0 |
| 46 | EOF |
| 47 | |
| 48 | systemctl daemon-reload |
| 49 | systemctl enable serial-getty@ttyS0.service |
| 50 | |
| 51 | # Disable password root login |
| 52 | usermod -p '!' root |
| 53 | |
azvyagintsev | bbae035 | 2018-10-09 21:11:22 +0300 | [diff] [blame] | 54 | # Drop default 'ubuntu' user |
| 55 | userdel -rf ubuntu |
| 56 | |
Richard Felkl | d59c565 | 2018-02-08 13:14:05 +0100 | [diff] [blame] | 57 | # Disable SSH password authentication and permit root login |
| 58 | sed -i 's|[#]*PasswordAuthentication yes|PasswordAuthentication no|g' /etc/ssh/sshd_config |
Ivan Berezovskiy | 41a6b82 | 2018-09-11 18:02:29 +0400 | [diff] [blame] | 59 | sed -i 's|[#]*PermitRootLogin.*|PermitRootLogin no|g' /etc/ssh/sshd_config |