SSH login without password

[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 login without password

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

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
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

ssh login without passwordOf 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]

11 thoughts on “SSH login without password”

    • 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

      Reply
  1. 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

    Reply
  2. 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.

    Reply
    • Perhaps you should check some of our guides related to firewall set up at https://www.rosehosting.com/blog/?s=firewall&submit=

      Reply

Leave a Comment