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 |
|
This will create a public and private key pair in the .ssh
directory, typically located at:
1 |
|
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 |
|
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 |
|
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 |
|
Step 4: Test the Connection
Now, you can test the password-free connection by running:
1 |
|
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
andauthorized_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.