Setting up SSH access on server and logging in via SSH without a password
On your local computer, in your home directory, find the .ssh folder, if it doesn't exist, create it.
mkdir ~/.ssh
For the first login via SSH, we write in the terminal
ssh username@your.ip.address
When a question appears, do this:
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Be sure to answer yes not y
After this:
The key will be saved in ~/.ssh/known_hosts
SSH will ask for the user's password.
Now, to log in via SSH without a password on the local machine, we create a key in the .ssh directory
ssh-keygen -t rsa -b 4096 -a 100
You can protect your SSH key with a passphrase at the next prompt. This is recommended for added security.
~/.ssh/id_rsa
~/.ssh/id_rsa.pub
We copy these keys to the server
ssh-copy-id username@your.ip.address
Enter your password one last time.
Done. The key has been added to
/home/username/.ssh/authorized_keys
Close the connection:
exit
Let's connect again
ssh username@your.ip.address
If it doesn't ask for a password, everything works.
Strengthening Security (Highly Recommended)
Open the file on the server
sudo nano /etc/ssh/sshd_config
And add
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
If you want to disable root login add
PermitRootLogin no
Now let's close the current session
sudo systemctl restart ssh
Login summary
✔️ SSH key only
❌ Password disabled
❌ Rooting via SSH is prohibited
✔️ Rooting is available via:
sudo -i