Set up password-free connection to remote server

Setting up a password-free connection to a remote server can simplify your workflow and improve efficiency. This guide will walk you through the steps to achieve this using SSH keys.

Step 1: Generate an SSH Key Pair

On your local machine, generate an SSH key pair using the following command:

1
ssh-keygen -t rsa

This will create a public and private key pair in the .ssh directory, typically located at:

1
C:\Users\USER_NAME\.ssh

The public key will be saved as id_rsa.pub. This is the key you will share with the remote server.

Step 2: Copy the Public Key to the Remote Server

On Linux

To view the contents of your public key, use the following command:

1
cat ~/.ssh/id_rsa.pub

Copy the output of this command. This is your public key.

On Windows

Navigate to the .ssh directory and open the id_rsa.pub file in a text editor. Copy the contents of the file.

Step 3: Add the Public Key to the Remote Server

Log in to your remote server and append the public key to the authorized_keys file:

1
echo "your-public-key-content" >> ~/.ssh/authorized_keys

Replace your-public-key-content with the actual content of your id_rsa.pub file.

Note: The >> operator appends the key to the file without overwriting existing keys.

Ensure the permissions for the .ssh directory and authorized_keys file are set correctly:

1
2
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Step 4: Test the Connection

Now, you can test the password-free connection by running:

1
ssh username@remote-server

If everything is set up correctly, you should be able to log in without being prompted for a password.

Troubleshooting

  • Ensure the SSH service is running on the remote server.
  • Verify that the authorized_keys file is in the correct location (~/.ssh/authorized_keys).
  • Check file and directory permissions for .ssh and authorized_keys.

By following these steps, you can securely set up a password-free connection to your remote server, making your workflow more seamless and efficient.


Set up password-free connection to remote server
https://www.hardyhu.cn/2024/09/28/Set-up-password-free-connection-to-remote-server/
Author
John Doe
Posted on
September 28, 2024
Licensed under