Setting Up SSH Key-Based Authentication in OpenSSH
SSH key-based authentication is a more secure alternative to password authentication. This guide will walk you through setting up SSH key-based authentication in OpenSSH.
Step 1: Generate SSH Key Pair
Generate an SSH key pair on your local machine.
ssh-keygen -t rsa -b 4096
This command creates a public key (id_rsa.pub
) and a private key (id_rsa
) in the ~/.ssh
directory.
Step 2: Copy Public Key to Remote Server
Copy your public key to the remote server.
ssh-copy-id user@hostname
This command adds your public key to the ~/.ssh/authorized_keys
file on the remote server.
Step 3: Verify SSH Key Authentication
Attempt to log in to the remote server using SSH key authentication.
ssh user@hostname
If successful, you will not be prompted for a password.
Step 4: Disable Password Authentication
For added security, disable password authentication by editing the SSH configuration file on the remote server.
sudo vim /etc/ssh/sshd_config PasswordAuthentication no
Restart the SSH service to apply the changes.
sudo service ssh restart
By following these steps, you can set up SSH key-based authentication, enhancing the security of your SSH connections.
No comments:
Post a Comment
Please keep your comments relevant.
Comments with external links and adult words will be filtered.