How to Connect to SSH Without a Password

Secure shell protocol (SSH) enables secure data connection and remote command execution. Here’s how to configure SSH for passwordless logins. 

Written by Mohamed Khey
Published on Feb. 20, 2024
Set of three keys on a table
Image: Shutterstock / Built In
Brand Studio Logo

Secure shell (SSH) protocol is a cryptographic protocol for secure data connection and remote command execution.

Configuring SSH Login Without a Password Explained in 5 Steps

  1. Verify that the SSH server is running.
  2. Connect to your remote machine.
  3. Generate private and public keys.
  4. Copy the public key file to the remote machine.
  5. Login to your server using SSH keys.

In this article, we are going to see how to configure SSH for a passwordless login to a remote machine.

 

5 Steps to Configure SSH Without a Password

There are five steps to configuring an SSH for passwordless login. Let’s look at each one:

 

1. Verify That the SSH Server Is Running

Run the following command to start the SSH service: $ sudo service sshd start or $ sudo systemtcl start sshd.

Check service status using: $ sudo service sshd status or $ sudo systemctl status sshd.

Run the following command to make sure that the secure shell daemon (SSHD) service is still active when you restart your system: $ sudo chkconfig sshd on.

More on Software DevelopmentHow to Convert Jupyter Notebook to PDF

 

2. Connect to Remote Machine

Run the command $ ssh remote_username@remote_server_ip_address. If this is the first time you’ve logged into this host, you will get a message like this:

The authenticity of host XXXXXX can’t be established.

RSA key fingerprint is 7c:e7:51:3b:86:70:07:ab:65:a9:bf:2d:c0:7b:1b:a7.

Are you sure you want to continue connecting (yes/no)?

Type “yes,” and then it will ask you to enter the password for the admin user to log in to the machine. Congratulations, you’re now connected to the remote machine with the password. But our goal is to make it passwordless. Don’t panic, we’ll cover that in the next few steps.

 

3. Generate Private and Public Keys

Let’s return to our localhost machine. A key-pair must be created with the command: $ ssh-keygen

This can be created on a Windows computer by using the command line or an SSH client like PuTTY.

Press “Enter” three times until the command finishes. A public key file “~/.ssh/id_rsa.pub” and a private key file “~/.ssh/id_rsa” will be generated.

 

4. Copy the Public Key File to the Remote Machine

Now that you’ve generated an SSH key pair, in order to be able to login to your machine without a password, you need to copy the public key to the server you want to manage.

$ ssh-copy-id remote_username@remote_server_ip_address
A tutorial on how to configure SSH for passwordless logins. | Video: Tony Teaches Tech

More on Software DevelopmentWhat Is WSGI (Web Server Gateway Interface)?

 

5. Login to Your Server Using SSH Keys

You should be able to get onto the remote server without being requested for a password once you’ve followed the preceding instructions.

To test it, try logging into your server via SSH:

$ ssh remote_username@remote_server_ip_address

Copying the server’s IP address using your ssh remote username. If everything went well, you will be logged in immediately.

With that, you’ve learned how to set up SSH key-based authentication, which enables you to connect to your remote server without entering a user password. The same key can be added to numerous remote servers, allowing you to connect to them without a password.

Explore Job Matches.