The cart is empty

Passwordless login using SSH keys offers a secure and convenient way to connect to a remote server. It eliminates the need to enter a password each time you log in while providing a higher level of security. In this article, you will learn how to configure SSH keys for passwordless login.

Generating SSH Keys

The first step is to generate a pair of SSH keys (public and private) on your local computer.

  1. Open a terminal.
  2. Use the ssh-keygen command to create a new key pair. You can specify the key type using the -t parameter, for example, ssh-keygen -t rsa -b 4096, where -b specifies the key length.
  3. During the process, you will be prompted to enter the location where you want to save the keys (usually .ssh/id_rsa) and optionally set a passphrase for the private key.

Uploading the Public Key to the Server

Next, you need to upload the public key to the target server.

  1. Use the ssh-copy-id user@server command, where user is your username on the server and server is the server's address. This command will automatically add your public key to the ~/.ssh/authorized_keys file on the server.
  2. If you cannot use ssh-copy-id, you can upload the public key manually. First, display the contents of the public key using cat ~/.ssh/id_rsa.pub, copy it, log in to the server, and paste it into the ~/.ssh/authorized_keys file.

SSH Server Configuration

To enable passwordless login, the server must be properly configured.

  1. Log in to the server.
  2. Open the SSH server configuration file using an editor, for example, sudo nano /etc/ssh/sshd_config.
  3. Check or modify the following lines:
    • PasswordAuthentication no disables password authentication.
    • PubkeyAuthentication yes enables authentication using public keys.
  4. After making changes, restart the SSH server, for example, with sudo systemctl restart ssh.

Testing Passwordless Login

Finally, test if passwordless login works:

  1. Try to connect to the server using ssh user@server.
  2. If you set a passphrase for your private key, you will be prompted to enter it. Otherwise, the connection should be established without entering a password.

 

Setting up passwordless login using SSH keys not only enhances the security of your connection to a remote server but also significantly simplifies the login process. By following the steps outlined above, you can easily configure SSH keys and enjoy the convenience of passwordless access.