This article will help you to Setup SSH Keys on Linux system. We can also say it passwordless ssh in Linux Systems using ssh key pair.
Step 1 – Generate SSH Key Pair
Firstly you would require generating a key pair (RSA or DSA), you can specify option rsa or dsa key using ‘t’ command line switch. If we do not pass -t parameter, it will create rsa key by default.$ ssh-keygen -t rsa
Generating public/private rsa key pair. Enter file in which to save the key (/home/rahul/.ssh/id_rsa): Created directory '/home/rahul/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/rahul/.ssh/id_rsa. Your public key has been saved in /home/rahul/.ssh/id_rsa.pub. The key fingerprint is: SHA256:GZQ3tJffEUimdMZHIG3LcpvdkOaogwXBtWeaM2ejzYY rahul@tecadmin The key's randomart image is: +---[RSA 2048]----+ | ..+oo+*+o | | .+ +o** ..| | .oooB oo | | .o B =+..| | S.= *+=.o| | .X.+...| | oE.+ | | . o. | | . | +----[SHA256]-----+The above command will create two files in the ~/.ssh directory as followings.
- ~/.ssh/id_rsa [private key]
- ~/.ssh/id_rsa.pub [public key]
Step 2 – Copy Public Key to Remote System
Lets copy our public key of our system to remote systems ~/.ssh/authorized_keys key file. We can do this manually or using ssh-copy-id command line tool.$ ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.10.20Sample Output:
21 root@192.168.10.20's password: Now try logging into the machine, with "ssh '192.168.10.20'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.Its will prompt for the password of the remote system. Enter remote machine password and press enter.
Step 3 – Verify SSH without Password
Now as we have all done, simply try to ssh to the remote system. You will log in to the remote system without entering the password.$ ssh root@192.168.10.20Above command will not prompt for the password to log in. In any case, if ssh command prompts for the password, it means your setup is not configured properly and try again all the steps again.
Comments
Post a Comment