blob: 8d7c8c12d8570c11f2942e16d2bf4515b9a6ed2f [file] [log] [blame]
Richard Felkld59c5652018-02-08 13:14:05 +01001#!/bin/bash -xe
Ivan Berezovskiy41a6b822018-09-11 18:02:29 +04002
3ROOT_AUTOLOGIN=""
4if [ "$(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"
11fi
Richard Felkld59c5652018-02-08 13:14:05 +010012
13# Libvirt serial console support
Ivan Berezovskiy41a6b822018-09-11 18:02:29 +040014cat << EOF >> /etc/systemd/system/serial-getty@.service
Richard Felkld59c5652018-02-08 13:14:05 +010015[Unit]
16Description=Getty on %I
17Documentation=man:agetty(8) man:systemd-getty-generator(8)
18Documentation=http://0pointer.de/blog/projects/serial-console.html
19After=systemd-user-sessions.service plymouth-quit-wait.service
20After=rc-local.service
21
22Before=getty.target
23IgnoreOnIsolate=yes
24
25ConditionPathExists=/dev/ttyS0
26
27[Service]
Ivan Berezovskiy41a6b822018-09-11 18:02:29 +040028ExecStart=-/sbin/agetty ${ROOT_AUTOLOGIN} -8 --noclear %I 115200 \$TERM
Richard Felkld59c5652018-02-08 13:14:05 +010029Type=idle
30Restart=always
31RestartSec=0
32UtmpIdentifier=%I
33TTYPath=/dev/%I
34TTYReset=yes
35TTYVHangup=yes
36TTYVTDisallocate=yes
37KillMode=process
38IgnoreSIGPIPE=no
39SendSIGHUP=yes
40
41Environment=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]
44WantedBy=getty.target
45DefaultInstance=ttyS0
46EOF
47
48systemctl daemon-reload
49systemctl enable serial-getty@ttyS0.service
50
51# Disable password root login
52usermod -p '!' root
53
azvyagintsevbbae0352018-10-09 21:11:22 +030054# Drop default 'ubuntu' user
55userdel -rf ubuntu
56
Richard Felkld59c5652018-02-08 13:14:05 +010057# Disable SSH password authentication and permit root login
58sed -i 's|[#]*PasswordAuthentication yes|PasswordAuthentication no|g' /etc/ssh/sshd_config
Ivan Berezovskiy41a6b822018-09-11 18:02:29 +040059sed -i 's|[#]*PermitRootLogin.*|PermitRootLogin no|g' /etc/ssh/sshd_config