1.8 KiB
1.8 KiB
Ubuntu Server 3.1: Remote SSH access
Who may log in over SSH, key-only logins in a drop-in that wins, and a second port.
Before you start
The lab only saves the SSH configuration, so reset can put it back. Start
it with sudo from your own account: task 1 lets in only one group, and
your account must be in it. Keep a second SSH session or the console open
while you change sshd, in case you lock yourself out.
"Your key" is a key pair of your own account on this VM, in ~/.ssh/;
make one with ssh-keygen if you have none. Leave its passphrase empty,
so the check can log in with it as you.
Tasks
- Create users
annandben, each with a password and your key inauthorized_keys. Allow SSH logins only for members of a new groupremote, and put ann and your own account in it, but not ben.ssh -o BatchMode=yes ann@localhost trueworks; the same for ben fails, andsudo journalctl -u sshsays ben's groups aren't listed in AllowGroups. - Turn off password logins for everyone, and root logins completely, in a
drop-in that wins over the cloud image's own files.
ssh -o PubkeyAuthentication=no ann@localhostfails withPermission denied (publickey). - Make sshd listen on port 2222 as well as 22.
ss -tlnlists:2222, andssh -p 2222 ann@localhost trueworks.
Hints
useradd -m -s /bin/bash,passwd;install -d -m 700 -o ann -g ann~ann/.ssh, thenauthorized_keyswith mode 600, owned by the user.groupadd,usermod -aG;AllowGroups.ls /etc/ssh/sshd_config.d/: the first value sshd reads wins, so give your file a name that sorts first.sudo sshd -t,sudo sshd -T | grep -E '^(passwordauthentication|permitrootlogin)',systemctl reload ssh.Port 22andPort 2222; on 24.04ssh.socketowns the port:systemctl daemon-reload,systemctl restart ssh.socket.