[et_pb_section bb_built=”1″][et_pb_row][et_pb_column type=”4_4″][et_pb_text _builder_version=”3.1.1″ text_font=”Open Sans||||||||”]
SSH or Secure SHELL is the most popular and trusted UNIX-based cryptographic network protocol. It can be used for secure data communication, remote server logins, remote command execution, and many other secure network services between two networked servers. Normally, password authentication is used to connect to a remote server via SSH. In this blog tutorial we will show you how to login to a remote Linux VPS without password, using SSH keys. This method is more secure than using a password.
SSH login without password
First of all, we need to generate the public and private keys. We will use the RSA (Rivest-Shamir-Adleman) cryptosystem.
ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): PRESS ENTER Enter passphrase (empty for no passphrase): PRESS ENTER Enter same passphrase again: PRESS ENTER Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 4a:91:e0:19:89:37:41:ce:3e:ff:56:2c:02:eb:65:cb root@LOCALSERVER The key's randomart image is: +--[ RSA 2048]----+ | o=o | | .+++ . | | .=.o | | .. . | | oo. S. | | .++.. o | | . +oo o | | . E.. | | .. | +-----------------+
This will create 2048 bit public and private keys in the ‘/root/.ssh/’ directory on your server
ls /root/.ssh/ id_rsa id_rsa.pub
Create a new ‘.ssh’ directory on the remote server
ssh root@REMOTE_SERVER mkdir -p .ssh
Copy the newly generated public key to the remote server you want to SSH without password
cat /root/.ssh/id_rsa.pub | ssh root@REMOTE_SERVER 'cat >> /root/.ssh/authorized_keys'
Change the permissions of the public key and the ‘.ssh’ directory
ssh root@REMOTE_SERVER "chmod 700 .ssh; chmod 600 .ssh/authorized_keys"
Now, login to the remote server and configure the SSH server to accept key authentication. Open the SSH configuration file
nano /etc/ssh/sshd_config
And make sure that the following three options are not commented and ‘RSAAuthentication’ and ‘PubkeyAuthentication’ are set to ‘yes’.
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile %h/.ssh/authorized_keys
Save the changes and restart the SSH server
/etc/init.d/sshd restart
That’s all. You should be able to the remote server without password
ssh REMOTE_SERVER
Of course, you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to explain or set up SSH login without a password. They are available 24×7 and will take care of your request immediately. You can also read our update on how to Disable or Enable SSH Root Login and Secure SSH Access in CentOS 7.
PS. If you liked this post on SSH login without password, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.
[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]
To copy key to remote machine beter use ssh-copy-id
Hi Max,
Yes, we completely agree that using
ssh-copy-id user@hostname
is another way of copying the key to the remote machine.Thanks
It is:
ssh-copy-id -i ~/.ssh/id_rsa.pub REMOTE_SERVER
Very helpful
Thanks for sharing!
Might as well create a 4096 bit RSA key.
(ssh-keygen -t rsa -b 4096)
I tried this “ssh: Could not resolve hostname remote_server: Name or service not known” but it says here that “ssh: Could not resolve hostname remote_server: Name or service not known” i am new to linux please help
Hi Rae,
Please use your actual hostname or IP address instead of ‘remote_server’.
Thanks worked great for me. I still have problems with setting up my firewall in mint that allows traffic from just a few machines that need ssh, http, and mariadb. It would be very helpful to supplement this article with setting up a secure firewall that allows traffic from specific machines. I cannot deny and allow at the same time. I know Im missing something.
Perhaps you should check some of our guides related to firewall set up at https://www.rosehosting.com/blog/?s=firewall&submit=
I have no “RSAAuthentication yes” line in the sshd_config file.
should I add it to the file?
RSAAuthentication by default is set to yes so there is no need to add it in the sshd_config file.