Generate SSH Keys in Linux (Fedora 35)
RSA
The simplest way is to execute the following command:
ssh-keygen -t rsa
This is how the whole process looks like in console. Please note that I did override the default key-pair location.
[terminator@fedora ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/terminator/.ssh/id_rsa): /home/terminator/test-ssh/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/terminator/test-ssh/id_rsa
Your public key has been saved in /home/terminator/test-ssh/id_rsa.pub
The key fingerprint is:
SHA256:VWjMnVqPPaY0y9iHvWpYG/JqJnSV2pZTZDkrlmARrtY terminator@fedora.home
The key's randomart image is:
+---[RSA 3072]----+
| oo=.. . |
| .B.+ = |
| oo+ O o |
| +. X B |
| S EX @ . |
| .. = & o |
| . . * = . |
| . + + . |
| +.o.. |
+----[SHA256]-----+
The private key looks like this:
[terminator@fedora ~]$ cat test-ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABCykTrbjR
Ytph1wo+yz0wmmAAAAEAAAAAEAAAGXAAAAB3NzaC1yc2EAAAADAQABAAABgQC8UtzH0Zlo
47uY/tsY/vCM4qWEuOidNOgFoujl0Ol32HcOMD8rqrUvnpa0j1INIGaCeTIWSmd6q2z35/
2s41BBIFzP9jtwukmiikXpeWeQgR0Td5vfIyOBupdfnrJd4rut0tBA9Kiz0GiKskZLK9HJ
Ce2+hiqVwhPaLi4CTyhi6V+ZxA5g6126LC1Rh6XJRw7wlMuQ3XtenFLhRrw6JEyOOKa9ck
MUEpAHCRIhWBmCIBmRIu8zo6Kn6pCi8ylC29zG8mqpBCAtXM7Ox53nfzO+VgQP4Zk5Eseu
JBw2TbOhCtgx8wX+Xx6lD5m2Fm8NoYSVNkJWI6yGabyZGqorwGYgOA9YFqLA04EH/Y05if
eVCUCh0E8smcBqFgyX6mmcJo3nZwsB02o3cTAIQA63WaAoiONitb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lo47uY/tsY/vCM4qWEuOidNOgFoujl0Ol32HcOMD8rqrUvnpa0j1INIGaCeTIWSmd6q2z35/2s41BBIFzP9jtwukmiikXpeWeQgR0Td5vfIyOBupdfnrJd4rut0tBA9Kiz0GiKskZLK9HJCe2+hiqVwhPaLi4CTyhi6V+ZxA5g6126LC1Rh6XJRw7wlMuQ3XtenFLhRrw6JEyOOKa9ckMUEpAHCRIhWBmCIBmRIu8zo6Kn6pCi8ylC29zG8mqpBCAtXM7Ox53nfzO+VgQP4Zk5EseuJBw2TbOhCtgx8wX+Xx6lD5m2Fm8NoYSVNkJWI6yGabyZGqorwGYgOA9YFqLA04EH/Y05ifeVCUCh0E8smcBqFgyX6mmcJo3nZwsB02o3cTAIQA63WaAoiONitbYx73vJdlZDK6V38B+qWmW+yrwphLhSCYmzuw/WeMLSH5ypQfgb1nSf3kGN4d2SDo+3dymcB6wOR5C/P2aavVs62V0TyyJ0V/uipq8= terminator@fedora.home
For all this to work properly you need to change some permissions:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
IMPORTANT: The above commands are executed in the default SSH directory (~/.ssh) rather than the directory where I saved the generated key-pair for the purpose of this test.
ED25519
This time we'll add a comment.
ssh-keygen -t ed25519 -C "key for www.some.website"
This is how the whole process looks like in console. Please note that I did override the default key-pair location.
[terminator@fedora ~]$ ssh-keygen -t ed25519 -C "key for www.some.website"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/terminator/.ssh/id_ed25519): /home/terminator/test-ssh/id_ed25519
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/terminator/test-ssh/id_ed25519
Your public key has been saved in /home/terminator/test-ssh/id_ed25519.pub
The key fingerprint is:
SHA256:62AnCelrYUJkZjwjSW0apHUtCN+zzRVOu/sOcHybOq0 key for www.some.website
The key's randomart image is:
+--[ED25519 256]--+
|+*o... o |
|++X=. .o o |
|.*=oo. + |
| .. * o . |
| . + + S . |
| ..o. + + o |
| o..= =.o |
| .o =.+. |
| .. E+o |
+----[SHA256]-----+
The private key looks like this:
[terminator@fedora ~]$ cat test-ssh/id_ed25519
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABD4d7UH7m
uxOnGtfPFaREOvAAAAEAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAIPNOrzsMd4heDBpj
2JCm8mPzB2Bm7N4yYeLIYdv7TKI/AAAAoEFI1sB908qbfyX0GsRIGFHl7VjrYAzzQgJ3Op
8sW/bGtNFBMB5SwWzxKWxk3kz9NU4jdpAXmqA0p1JxaCh/lwX6XtCnrTw1PLdjsHFPy2Br
SZLVuW4VTr4BfAniDTJL+18Gy3/eveAT0GHWk/wslET6xqfyDZ0rHKWK5zayPgH9zd3Xl+
9jrSt+XmPnwJLZuRvd+BuRwPn3tCDeTc9+2sM=
-----END OPENSSH PRIVATE KEY-----
The public key looks like this:
[terminator@fedora ~]$ cat test-ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPNOrzsMd4heDBpj2JCm8mPzB2Bm7N4yYeLIYdv7TKI/ key for www.some.website
As mentioned before, for all this to work properly you need to change some permissions:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
IMPORTANT: The above commands are executed in the default SSH directory (~/.ssh) rather than the directory where I saved the generated key-pair for the purpose of this test.
Sources: