To enable passwordless SSH access to a remote machine, you can manually copy your public SSH key into the
~/.ssh/authorized_keys
file for the user you want to connect as.
Steps
-
Generate an SSH key (if you haven't already):
This will create two files inssh-keygen
~/.ssh/
:
-id_rsa
(private key)
-id_rsa.pub
(public key) -
Copy your public key to the remote machine:
You can do this manually using the following command:
Replacecat ~/.ssh/id_rsa.pub | ssh user@host "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
user
with the remote username andhost
with the IP address or domain name of the server. -
Test the connection:
If everything is set up correctly, you should connect without being prompted for a password.ssh user@host
Notes
- Make sure the
~/.ssh
directory andauthorized_keys
file on the remote machine have the correct permissions. - This method requires that you can still log in to the remote machine using a password at least once to add your key.
- Your private key (
id_rsa
) must stay secure and should never be shared.