How to Set Up SSH Passwordless Login (Step-by-Step Tutorial) | StrongDM (2024)

How to Set Up SSH Passwordless Login (Step-by-Step Tutorial) | StrongDM (1)

SSH is one of the best ways to handle tasks such as automated backups, file synchronization, and remote server access and management. SSH passwordless login is an SSH authentication method that employs a pair of public and private keys for asymmetric encryption. The public key resides on the server, and only a client that presents the private key can connect.

SSH does have its pain points, with or without SSH keys, including:

  • As employees come and go, new credentials (whether passwords or keys) must be created and old ones destroyed.
  • Credentials need to be rotated, a time-consuming and often overlooked process.
  • Auditing access can be a challenge. Wrapping communication in an SSH tunnel makes it more secure but also more difficult to track and control.

Fortunately, there’s an alternative to managing all of these things by hand, which we’ll go into later.

This tutorial will walk you step by step through how to manually set up SSH passwordless login to a Linux server. These commands should work on the majority of Linux distributions, and instructions are included for modern client machines of the macOS, Windows, and Linux varieties.

Step 1: Generate a key pair

Use ssh-keygen to generate a key pair consisting of a public key and a private key on the client computer. This command can be run on any modern Linux client distribution, the Terminal in macOS, or in the Command Prompt in Windows 10/11.

ssh-keygen -t rsa

The -t rsa option specifies that the type of the key should be RSA. Other choices include DSA, ECDSA, and ED25519. Select the protocol your SSH connection will use.

When prompted, enter a filename for the key.

Enter file in which to save the key. (C:\Users\annem_000\.ssh\id_rsa):

The default (id_rsa in the .ssh directory under the user’s home directory) works perfectly in most cases (and if this is to be your primary key, or only key, it is often the best option). Hit enter to accept the default (if you already have a key by this name, use whatever name you choose here throughout this tutorial in place of id_rsa). Then enter the passphrase when prompted.

Enter Passphrase (empty for no passphrase):


Adding a passphrase is an important step for securing the local key, which otherwise will be usable by anyone who acquires the key itself. Choose a passphrase with the same rigor that you would use to create any secure passphrase. Some clients can be configured to save passphrases for a true “passwordless” access experience, while others may require it to be entered with each use. This will be covered in more detail later in the tutorial.

Type a passphrase (it will not be displayed, even though you are correctly entering it) and hit Enter (or hit Enter to continue with the default of no passphrase). Confirm the passphrase when prompted. The result will look similar to this:

How to Set Up SSH Passwordless Login (Step-by-Step Tutorial) | StrongDM (2)


With the initial step to set up SSH passwordless login using ssh keygen completed, you now have two files:

  • id_rsa contains the private key.
  • id_rsa.pub contains the public key.

Step 2: Create SSH directory on server

Next, add the public key on the server you want to connect to. With your existing username and password, connect to the server using SSH, using whatever command line or client program you normally use for such connections. Check to see if the .ssh directory already exists by attempting to list the files within it:

ls .ssh

If it does not, you will not be able to move into that directory and should instead create it:

mkdir -p .ssh


(Note the required dot at the beginning of the directory name, which makes this a hidden directory.)

Step 3: Upload public key to remote server

Uploading your public key with a Linux or macOS client

On a macOS or Linux client, use ssh-copy-id to propagate the public key to the server, like this:

ssh-copy-id user@somedomain

Make sure to replace user with a valid username from the server and somedomain with the valid IP or domain of the server.

Uploading your public key with a Windows client

With a Windows client, you can accomplish this task via the Windows Command Prompt. You will need to refer to the results of your earlier attempt to list the contents of the .ssh directory and see if it contained a file called authorized_keys or not.

A) If you had to create the .ssh directory yourself, or if the remote server doesn’t already have an authorized_keys file, on the client computer command line, enter the following to copy the public key to the .ssh directory on the server (if you changed the name of your key from id_rsa.pub, change it here):

scp .ssh/id_rsa.pub user@somedomain:~/.ssh/authorized_keys


B) If the remote server has an existing authorized_keys file, the new key must be appended rather than overwriting the existing file. This is very important so that existing users do not lose access unintentionally. First, you will copy the file to the remote server. Then on the remote server, use the cat command to append it to the existing file:

On the client: scp .ssh/id_rsa.pub user@somedomain:~/.ssh

On the remote server: cat .ssh/id_rsa.pub >> .ssh/authorized_keys

On the remote server: rm .ssh/id_rsa.pub (clean up after yourself and remove the now-unnecessary key file)

Step 4: Test connection and configure an SSH agent

In your SSH session with the remote machine, update the permissions of the .ssh directory and authorized_keys file in case they need it:

chmod 700 ~/.ssh

chmod 600 ~/.ssh/authorized_keys


Now, close your connection and your Terminal or Command Prompt. When you reopen it and try to connect to the remote server again from the client where you have your private key saved, you should receive a request to enter the passphrase instead of your username and password. Test it out:

ssh user@somedomain


👍 Success! Now, to avoid entering the SSH key passphrase every time:

  1. You will need to use an SSH agent of some kind.

    For Windows: You will use the OpenSSH Authentication Agent. The agent can be started by searching in the Windows Start menu for "Services," then double click on "OpenSSH Authentication Agent." Set the startup type to "Automatic" and click "Start."; Click Ok and Exit.

    For macOS and Linux: The ssh-agent program already runs on session start for most Linux/Unix distributions. It provides an agent that you can add keys to and save passphrases. Once set up, the program will not require further interaction.

  2. At your command line prompt, in either case, type ssh-add. If you used the default id_rsa naming for your key, that’s all you have to do. If you used a passphrase for the key, it will prompt you to enter it. Now the agent will remember your key and passphrase, and you won’t need to enter it on each use. You can also get more specific when adding keys (for example, if you used a different name for your key) with ssh-add parameters.

Step 5: Back up SSH Keys

A public key can be re-derived from a private key, but not vice-versa, making it especially important to back up private keys. To do so, simply back up the directory where they reside, which in our above examples, was the .ssh directory in your user’s home directory. Both keys in the pair will be backed up because you generated them there, unless you removed one of them from the directory.

Optional Step: Disable password authentication

Most servers allow both username/password authentication and SSH key authentication, but if you want to allow only SSH key authentication, then you can disable the use of usernames and passwords. Be certain that you have thought through the ramifications before doing so, because once you take this action, successful certificate authentication will be the only way to access your server.

This is accomplished through the sshd_config file. The exact location of this file varies by Linux distribution. Often it’s in the /etc/ssh directory. Edit this file to include the following parameters:

PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no

Drawbacks of SSH Passwordless Logins

SSH passwordless login facilitates remote system login for off-site developers as well as on-site staff and scripted automation, but it comes with some potential complications:

  • Private SSH keys sit on the client disk, where they can potentially be stolen (if passphrase protected, this is less of an issue.)
  • SSH keys take a bit of work to set up and may require technical knowledge on the user’s end.
  • Distributing a user’s public key to all servers the user wishes to connect to becomes a cumbersome requirement in large environments.
  • Incorrect file permissions on the remote server can prevent SSH key authentication from working.
  • Compatibility problems can arise between versions of SSH. For example, a system running an older version of OpenSSH might require a different key type, such as DSA instead of RSA
  • Manual SSH key management consumes a lot of time and is open to errors, although this drawback is shared with the management of usernames and passwords for individual users and servers, as well.

Eliminate passwords with a control plane

Excellent access control and monitoring strategies are a crucial part of any infrastructure plan in today’s highly distributed environment. Yet manually distributing, revoking, rotating, and auditing SSH keys is a lot of work. Incorporating a good control plane is the answer:

  • It eliminates the need to provide SSH keys to individual users and administer them across multiple machines.
  • Centralizes credential management and access by role via an easy-to-use interface, making onboarding and offboarding simple.
  • Enables quick, secure access to any server, any database, local or remote.
  • Is compatible with every database, server OS, SSO provider, and cloud.
  • Logs every session, capture every query, command, and permission change with a protocol-aware proxy. These logs can’t be beaten for auditing abnormal activity or as a tool for meeting regulatory compliance.

StrongDM improves workflow and simplifies administration. If you’re ready to step away from the hassles of traditional SSH key management to more modern ways of authenticating, securing, and tracking access, give StrongDM a try. You’ll only need five minutes to connect to your first database or server.

How to set up certificate-based SSH

About the Author

Jeff Smith, Lead Technical Writer, has led projects and teams working on documentation in access and security for more than six years. Learning these technologies and helping other people do the same is his passion. Jeff contributes occasionally to various technical blogs and publications and sometimes writes on non-software topics such as productivity, project management, and tech news. To contact Jeff, visit him on LinkedIn.

How to Set Up SSH Passwordless Login (Step-by-Step Tutorial) | StrongDM (3)

💙 this post?

Then get all that StrongDM goodness, right in your inbox.

How to Set Up SSH Passwordless Login (Step-by-Step Tutorial) | StrongDM (2024)

FAQs

How to setup passwordless SSH for a user? ›

How to Set Up Passwordless SSH Login
  1. Before You Start: Check for Existing SSH Keys.
  2. Step 1: Generate SSH Key Pair.
  3. Step 2: Upload Public Key to Remote Server. Option 1: Upload Public Key Using the ssh-copy-id Command. ...
  4. Step 3: Log in to Server Without Password.
  5. Optional: Troubleshooting Remote Server File Permissions.
Apr 15, 2020

How must passwordless SSH be configured? ›

To set up passwordless SSH you must configure the mqm id on each node, then generate a key on each node for that user. You then distribute the keys to the other nodes, and test the connection to add each node to the list of known hosts.

How to make SSH work without password? ›

5 Steps to Configure SSH Without a Password
  1. Verify That the SSH Server Is Running.
  2. Connect to 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.
Feb 20, 2024

How to setup passwordless SSH access between nodes in a cluster? ›

  1. Step 1: Generate SSH Key Pair on Server A. Log in to Server A using SSH or physical access. ...
  2. Step 2: Copy the Public Key to Server B. Use the ssh-copy-id command to copy the public key to Server B: ssh-copy-id user@serverB_IP. ...
  3. Step 3: Test the Passwordless Connection.
Sep 12, 2023

How to setup passwordless SSH between Windows and Linux? ›

How to Setup Passwordless SSH Connect from Windows to Linux
  1. Your public key has been saved in C:\Users\[username]/. ssh/id_rsa. ...
  2. Open id_rsa. ...
  3. Connect to the destination server using ssh and your password from PowerShell.
  4. Open the “authorized_keys” file with vi:
Oct 9, 2020

How to set SSH password authentication? ›

Configure password-based SSH authentication
  1. Log in to the server console as the bitnami user.
  2. Edit the /etc/ssh/sshd_config and modify or add the following line: PasswordAuthentication yes.
  3. Restart the SSH server for the new configuration to take effect: sudo /etc/init.d/ssh force-reload sudo /etc/init.d/ssh restart.
Oct 10, 2022

How does passwordless login work? ›

Passwordless authentication is a means to verify a user's identity, without using a password. Instead, passwordless uses more secure alternatives like possession factors (one-time passwords [OTP], registered smartphones), or biometrics (fingerprint, retina scans).

How do you create a passwordless user in Linux? ›

Q: Is it possible to create a user without a password in Linux? A: Yes, you can create a user without a password in Linux. This is done by using the command “sudo useradd -U username”.

How to create SSH username and password? ›

Create SSH Credentials
  1. Enter a Credential Name.
  2. From the Type list, select SSH.
  3. Enter a Username.
  4. Select an Authentication Type: Password: Enter a password and confirm it. SSH-DSS Key: Upload a private key file. Enter key and confirm it if those fields are available.

How to login SSH without password PuTTY? ›

Set up passwordless login in PuTTY
  1. Open the puttygen.exe file you downloaded when configuring PuTTY. ...
  2. In the PuTTY Key Generator box, make sure the radio button at the bottom is selected for RSA.
  3. Click the Generate button.
  4. Move your mouse around the box to help generate the keys.
Mar 27, 2024

Is it safe to use SSH key without password? ›

If someone gains access to your private key, they can use it to log in to any server that has your public key without needing to know your password. This means that if your private key is stolen or compromised, all of your servers are at risk.

How to disable user password in SSH? ›

Disable Password Authentication
  1. vim /etc/ssh/sshd_config. Look for the line PasswordAuthentication yes and replace yes with no.
  2. PasswordAuthentication no. Press ESC key and save the changes to the file and exit the editor by typing: wq! and then hit Enter. ...
  3. service sshd restart.

How to use passwordless SSH login? ›

  1. Method 1: Using the ssh-copy-id Command. The basic syntax to use this command is as highlighted below: ssh-copy-id remote_username@remote_IP_Address. ...
  2. Method 2: Copy the Private Key Using SSH. The next method uses SSH to copy the private key. ...
  3. Method 3: Manually Copying the Public Key.

How to set up SSH key locally? ›

For Windows 10 & 11
  1. Press the Windows key or open up the Start Menu. Type “cmd”.
  2. Under “Best Match”, click “Command Prompt”.
  3. In the command prompt, use the ssh-keygen command: ...
  4. The system will now generate the key pair and display the key fingerprint and a randomart image. ...
  5. Open your file explorer.

How to configure key based authentication for SSH? ›

Procedure
  1. Use the ssh-keygen tool to create a key pair. ...
  2. Validate that the keys were generated. ...
  3. Enable key-based authentication in the /etc/ssh directory on the SSH server. ...
  4. Copy the rsa. ...
  5. If you have an existing authorized_keys file, edit it to remove any no-pty restrictions.

How to setup SSH for a user? ›

Add an SSH User
  1. Switch to the root user. sudo su –
  2. Create a new user. ...
  3. Create a directory named . ...
  4. Copy the authorized_keys file from the opc user's . ...
  5. Change the owner of the /home/username/. ...
  6. Edit the file /etc/ssh/sshd_config . ...
  7. Verify that there are no errors in your SSH configuration. ...
  8. Restart the SSH service.

How do you create a SSH key for a user? ›

Generate an SSH Key Pair
  1. Run the ssh-keygen command. You can use the -t option to specify the type of key to create. ...
  2. The command prompts you to enter the path to the file in which you want to save the key. ...
  3. The command prompts you to enter a passphrase. ...
  4. When prompted, enter the passphrase again to confirm it.

How do I SSH with a user password? ›

To connect to a server, do the following:
  1. Open the command line/terminal window and run the following ssh command: ssh [username]@[host_ip_address] ...
  2. When connecting to the server for the first time, a message appears asking to confirm the connection. ...
  3. Provide the password when prompted and press Enter.
Nov 23, 2023

How to make a user passwordless in Linux? ›

I want to create a user that I would be able to login from a regular user without password prompt.
  1. Run command: sudo visudo. ...
  2. Go down to the bottom of the file, add the following line: <user> ALL=(ALL) NOPASSWD: ALL. ...
  3. Save and exit the file.
  4. Run command: sudo -k. ...
  5. You're done!
  6. To test, run command: sudo ls.
Nov 17, 2019

Top Articles
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 5972

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.