How to add ssh key in vps

How to Add SSH Key in VPS

Adding an SSH key to your VPS is a secure and efficient way to authenticate yourself when accessing your server. In this guide, we will walk you through the steps to add an SSH key to your VPS.

What is an SSH Key?

SSH keys are a pair of cryptographic keys that can be used to securely connect to a remote server. The keys consist of a public key and a private key. The public key is stored on the server, while the private key is kept on your local machine. When you connect to the server, your local machine uses the private key to prove your identity.

Generating an SSH Key Pair

If you do not already have an SSH key pair, you can generate one using the ssh-keygen command. Simply open your terminal and run the following command:

ssh-keygen -t rsa -b 2048

Follow the prompts to create your SSH key pair. Once the keys are generated, you will have a public key (usually named id_rsa.pub) and a private key (usually named id_rsa) in your ~/.ssh directory.

Adding the SSH Key to Your VPS

To add your SSH key to your VPS, you will need to copy the contents of your public key and append it to the authorized_keys file on your server. You can do this by using the following command:

ssh-copy-id user@vps_ip_address

Replace user with your server’s username and vps_ip_address with the IP address of your VPS. You will be prompted to enter your password. Once your SSH key is added, you can log in to your server without entering a password.

Testing Your SSH Key

To test if your SSH key is working correctly, try connecting to your VPS using the following command:

ssh user@vps_ip_address

If you are able to connect without entering a password, your SSH key has been successfully added to your VPS.

Conclusion

Adding an SSH key to your VPS is a simple and secure way to authenticate yourself when accessing your server. By following the steps outlined in this guide, you can add an SSH key to your VPS in no time.

Comments