How to connect without a password via ssh?

To connect without a password via SSH, you can use public key authentication. Public key authentication is a secure and convenient way to log in to a remote server without entering a password each time.

Here’s a step-by-step guide to setting up passwordless SSH authentication:

1. Generate SSH key pair: On your local machine, generate an SSH key pair if you haven’t already done so. Open a terminal and run the following command:

ssh-keygen -t rsa

This will generate a pair of keys: a private key (usually id_rsa) and a public key (usually id_rsa.pub).

2. Copy the public key to the remote server: Use the following command to copy your public key to the remote server you want to connect to:

ssh-copy-id username@remote_host

Replace username with your username on the remote server and remote_host with the hostname or IP address of the remote server. You will be prompted for your password on the remote server.

If the ssh-copy-id command is not available on your system, you can manually append the content of your public key (id_rsa.pub) to the ~/.ssh/authorized_keys file on the remote server.

3. Configure SSH on the remote server: SSH server configuration should allow public key authentication. On the remote server, open the SSH server configuration file (usually located at /etc/ssh/sshd_config) using a text editor.

Locate the line that starts with #PubkeyAuthentication yes and remove the leading # to uncomment the line. If the line doesn’t exist, you can add it.

Save the changes and exit the text editor.

4. Restart SSH service: Restart the SSH service on the remote server to apply the changes you made to the configuration file. The command to restart SSH depends on your operating system. For example, on Ubuntu, you can use:

sudo service ssh restart

Alternatively, you can use the following command if you are using a system with systemd:

sudo systemctl restart sshd

5. Test the passwordless SSH login: Try to SSH into the remote server without a password:

ssh username@remote_host

Replace username with your username on the remote server and remote_host with the hostname or IP address of the remote server. If everything is set up correctly, you should be able to log in without entering a password.

That’s it! You have successfully set up passwordless SSH authentication. Now you can log in to the remote server without typing your password each time.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.