Adding SSH Key to Server
To add an SSH key to a server, you can follow these steps:
Generate an SSH key pair on your local computer using the ssh-keygen command. You can use the default settings or specify a custom key name and location. For example, to generate a key pair with a custom name and save it in a specific directory, you can use the following command:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f /path/to/key_name
Copy the public key to the server using the ssh-copy-id command. Replace username and server_ip_address with your server login credentials. You will be prompted for your server password.
ssh-copy-id -i /path/to/public_key username@server_ip_address
Once you have copied the public key to the server, you can log in to the server using your private key. To do this, use the ssh command with the -i option and the path to your private key. For example:
ssh -i /path/to/private_key username@server_ip_address
That's it! You should now be able to log in to the server using your SSH key instead of your password. Make sure to keep your private key secure and never share it with anyone.