Skip to content

SSH Keys

https://www.linode.com/docs/guides/use-public-key-authentication-with-ssh/

  1. 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
  1. Copy the newly-created key to the remote server
ssh-copy-id username@remote_host
  1. You will be prompted to authenticate with your password for the account in question. If successful, the key will be copied.
  2. Try to connect to the remote host again.
ssh username@remote_host
  1. 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

  1. Edit the sshd_config file in the text editor of your choice via the following command:
sudo nano /etc/ssh/sshd_config
  1. Locate the line that contains #PermitRootLogin yes and uncomment the # symbol and change the yes to no so it reads PermitRootLogin no
  2. You can also set the line to PermitRootLogin no-password (I think) to only allow logon via SSH auth keys
  3. 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