Generating and Using an SSH Key for Secure Server Access
To generate a strong SSH key, run the following command:
ssh-keygen -t ed25519 -C "ansible"
You will be prompted to choose a folder and name for the SSH key:
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/marcin/.ssh/id_ed25519): /home/marcin/.ssh/ansible/ansible
Next, copy the SSH key to the server(s) you want to access. However, before you do so, you must first log in to the server(s) using your name and password:
ssh-copy-id -i ~/.ssh/ansible.pub <IP Adderss>
Once you have copied the SSH key to the server, you can use it to connect securely:
ssh -i .ssh/<key_name> <IP Address>
To cache the passphrase for your session, you can use the ssh-agent:
eval $(ssh-agent) &&b ssh-add
Here’s an alias you can add to your .bashrc file to simplify the process:
alias ssha='eval $(ssh-agent) && ssh-add'
Conclusion:
Generating and using SSH keys can greatly enhance the security and convenience of remote server access. With the steps outlined above, users can create a strong SSH key, copy it to the desired server(s), and use it to establish secure connections. Additionally, the use of ssh-agent and aliases can simplify the process and make it more efficient. By following these best practices, users can mitigate the risks associated with traditional username/password authentication methods and ensure the confidentiality, integrity, and availability of their systems.
Useful links:
For more information on SSH key generation and usage, you can visit https://www.ssh.com/academy/ssh/keygen