DEV Community

Tonny Kirwa
Tonny Kirwa

Posted on

Login to Ubuntu Remote Server - Passwordless via SSH Only

To make SSH passwordless and allow only key-based authentication (no password authentication), you'll need to perform the following steps:

  1. Generate an SSH Key Pair (if not already done):

If you haven't already generated an SSH key pair, you can do so with the following command on your local machine:

   ssh-keygen -t rsa -b 4096
Enter fullscreen mode Exit fullscreen mode

This will create an SSH key pair in your ~/.ssh directory, typically named id_rsa (private key) and id_rsa.pub (public key).

  1. Copy the Public Key to the Remote Server:

Use the ssh-copy-id command to copy your public key to the remote server. Replace username with your username on the remote server and remote_server_ip with the server's IP address or hostname:

   ssh-copy-id -i ~/.ssh/id_rsa.pub username@remote_server_ip
Enter fullscreen mode Exit fullscreen mode

You'll be prompted to enter your remote server password for this step.

  1. Disable Password Authentication on the Remote Server:

To ensure that only key-based authentication is allowed, you should disable password authentication on the remote server. Edit the SSH server configuration file on the remote server with a text editor. You can use nano, vim, or any text editor you prefer:

   sudo nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode

Find the following line:

   #PasswordAuthentication yes
Enter fullscreen mode Exit fullscreen mode

Uncomment it (remove the #) and change it to:

   PasswordAuthentication no
Enter fullscreen mode Exit fullscreen mode

Save and exit the text editor.

  1. Restart the SSH Service:

To apply the changes, restart the SSH service on the remote server:

   sudo systemctl restart ssh
Enter fullscreen mode Exit fullscreen mode
  1. Test SSH Login:

Try to SSH into the remote server from your local machine. It should now only allow key-based authentication and not prompt for a password:

   ssh username@remote_server_ip
Enter fullscreen mode Exit fullscreen mode

You should be able to log in without a password.

By following these steps, you've configured SSH to allow only key-based authentication and disabled password authentication on the remote server, making SSH passwordless for your login sessions.

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more