How to use SSH key to Connect Remote Server?

How to use SSH key to Connect Remote Server?

To connect to a remote server using a key pair and the command line, use the ssh command. Here's a simple example:

ssh -i /path/to/private-key.pem username@remote-server-ip

Replace /path/to/private-key.pem with your private key file's location, username with your remote server username, and remote-server-ip with the IP address or hostname of the remote server.

If your private key is in the default location (usually ~/.ssh/id_rsa), you can omit the -i option:

ssh username@remote-server-ip

Make sure you have the necessary permissions set on your private key file:

chmod 600 /path/to/private-key.pem

This command restricts access to the private key to the owner only.

If you run into any problems, you can also use the -v option for detailed output to help find issues:

ssh -v -i /path/to/private-key.pem username@remote-server-ip

This will show more information about the SSH connection process, which can help with fixing problems.