SSH Keys
https://www.linode.com/docs/guides/use-public-key-authentication-with-ssh/
- Create an SSH key on the device you would like to connect from
ssh-keygen
ssh-keygen -t rsa -b 4096
ssh-keygen -t ed25519
- Copy the newly-created key to the remote server
ssh-copy-id username@remote_host
- You will be prompted to authenticate with your password for the account in question. If successful, the key will be copied.
- Try to connect to the remote host again.
ssh username@remote_host
- If the previous steps were successful, you should be connected via the SSH key and not be prompted for password.
Disable login for root account
- Edit the sshd_config file in the text editor of your choice via the following command:
sudo nano /etc/ssh/sshd_config
- Locate the line that contains
#PermitRootLogin yesand uncomment the # symbol and change theyestonoso it readsPermitRootLogin no - You can also set the line to
PermitRootLogin no-password(I think) to only allow logon via SSH auth keys - Once root login has been disabled, you can make the change active by running any of the following commands:
/etc/init.d/sshd restart
systemctl restart sshd
service sshd restart