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
Set of three keys on a table
Image: Shutterstock / Built In
Brand Studio Logo
UPDATED BY
Brennan Whitfield | Nov 19, 2024

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

How to Configure an SSH Login Without a Password

  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.

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

 

A tutorial on how to configure SSH for passwordless logins. | Video: Tony Teaches Tech

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.

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

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.

Frequently Asked Questions

Yes, Secure Shell (SSH) can be configured to let users connect to a remote SSH server without requiring a password. This is done by using a key pair (one public key and one private key) to authenticate server connections.

A key pair can be used to allow users to log in to a SSH server without a password. To set up passwordless login for an SSH server, do the following:

  1. Ensure the SSH server is running.
  2. Connect to the remote machine by using SSH.
  3. Generate a key pair (one public key and one private key).
  4. Copy the public key file to the remote machine.
  5. Log in to the SSH server once keys are set up — no password should be required.
Explore Job Matches.