SSH Key Authentication Ubuntu 20.04
Oct 31, 2021
·
2 mins read
In the video below, we show how to create and authorize SSH edb25519 keys to login to a Linux server running Ubuntu server 20.04 for example
SSH keys are a more secure method of authentication than using a username and password and edb25519 is a more modern and less intensive algorithm then RSA
We show how to generate an SSH key pair, how to upload the public key to the server, how to disable password authentication on the server to enforce SSH key authentication and how to create a config file to simplify logins when you have multiple keys for instance
Useful links:
https://www.ssh.com/academy/ssh/config
Steps taken:
-
Generate SSH key pair on workstation
Where ed25519 is the encryption algorithm we’ll use, test-key is the identity we’ll give this key pair and test@test.com is a comment we’ll attach to thiscd ~/.ssh ssh-keygen -t ed25519 -f test-key -C "test@test.com"
-
Distribute and authorize key for authentication
Where test-key is the identity of the key we want authorizing for the user account test on the server 192.168.1.20ssh-copy-id -i test-key test@192.168.1.20
-
Disable password authentication on server
Look for a line sayingsudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak sudo nano /etc/ssh/sshd_config
Change this toPasswordAuthentication yes
NOTE: Ubuntu servers have one line with this commented out and another which is active. We want to change the active onePasswordAuthentication no
Restart SSHThen check the service is still workingsudo systemctl restart sshd
sudo systemctl status sshd
-
Use the SSH config file on the workstation to manage multiple keys
touch config chmod 600 config nano config
NOTE: In the above example, Fred is the user account we’re logged into on the workstation where SSH is being used, but we login to different servers using different user names and different keysHost * IdentitiesOnly yes Host server1 HostName 192.168.1.20 User test IdentityFile "/home/fred/.ssh/test-key" Host server2 HostName server2.test.com User prod IdentityFile "/home/fred/.ssh/prod-key"
These are just examples of what is possible though as it is not recommened to leave usernames in the config file in case somebody gains access to it
Sharing is caring!