How to generate ssh keys for logged-in user on Linux Fedora 37 / Centos 9 / RHEL9

How to generate ssh keys for logged-in user on Linux Fedora 37 / Centos 9 / RHEL9

We can create ssh keys (public / private key pair) for currently logged in user on Linux using the ssh-keygen utility.

[test_user@fedora ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/test_user/.ssh/id_rsa): 
Created directory '/home/test_user/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/test_user/.ssh/id_rsa
Your public key has been saved in /home/test_user/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:NmvMPVbwXCskt30Ai9Kc5tUDv6AOQQVlqJksm6SZXUo test_user@fedora
The key's randomart image is:
+---[RSA 3072]----+
|        o=+ o    |
|       ..+ o *   |
|     . +o O * *  |
|    E *  = X = = |
|   B *  S o * + .|
|  + =  + * . . . |
|        = =      |
|       . . .     |
|                 |
+----[SHA256]-----+

ssh keys are generated and check whether keys exist in the .ssh directory under user home directory.

[test_user@fedora ~]$ ls ~/.ssh/

Lists rsa private key ‘id_rsa’ and public key ‘id_rsa.pub’,

authorized_keys  id_rsa  id_rsa.pub  known_hosts

How to copy ssh key to target sysyem on Linux Fedora 37?

Now we can copy public key to target system using ssh-copy-id command,

[test_user@fedora ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub test_user@localhost

Prompt password and copy’s public key to target machine.

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/test_user/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
test_user@localhost's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'test_user@localhost'"
and check to make sure that only the key(s) you wanted were added.

Now try ssh connection, should not ask password for test_user in target system.

[test_user@fedora ~]$ ssh test_user@localhost

1 device has a firmware upgrade available.
Run `fwupdmgr get-upgrades` for more information.

Last login: Mon Mar 20 02:04:38 2023 from ::1
[test_user@fedora ~]$ 




Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^