SSH keys are cryptographic keys that enable user authentication to servers, providing a secure alternative to traditional passwords. They not only increase security but also greatly simplify daily tasks for developers.
By employing an SSH key, you can:
Elevate the security of your environment by disabling regular password access and mandating a passphrase-protected SSH key.
Streamline your login process by either eliminating the need for a password or opting for a passphrase simpler than those typically necessary for secure SSH logins, although it's crucial to note that this isn’t a best practice and should be reserved for less critical setups, such as personal home networks.
Moreover, platforms like Visual Studio Code and GitHub support remote SSH sessions using key authentication, ensuring secure and seamless remote coding experiences.
This introduction is a gateway to a series focused on SSH keys. Below is a quick guide containing essential commands to generate and use SSH keys swiftly. For those interested in diving deeper into the details, refer to Creating SSH Keys which is the next article in this series.
ssh-keygen -t rsa -b 4096
Windows (PowerShell as administrator):
Add-WindowsCapability -Online -Name OpenSSH.Client Get-Service -Name ssh-agent | Set-Service -StartupType Automatic ssh-keygen -t rsa -b 4096
Enter for default settings and decide whether to set a passphrase.
eval $(ssh-agent -s) ssh-add ~/.ssh/id_rsa
Start-Service ssh-agent ssh-add ~\.ssh\id_rsa
For a server with the address
Windows using Powershell:
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh user@host "cat >> .ssh/authorized_keys"
Append the public key (
~/.ssh/id_rsa.pub) content to
on the server.
If everything is set up correctly, you should be able to log into the server without entering a password.
After ensuring that the SSH key-based access is successful:
- Edit the SSH configuration:
sudo nano /etc/ssh/sshd_config
- Change the line
- Restart the SSH service:
sudo systemctl restart sshd
Copy the public key content:
cat ~/.ssh/id_rsa.pub | xclip -selection clipboard
Windows (Git Bash):
clip < ~/.ssh/id_rsa.pub
Get-Content ~/.ssh/id_rsa.pub | Set-Clipboard
Go to GitHub account settings > "SSH and GPG keys" > "New SSH key". Paste the copied key and save.
That's it! You've quickly set up SSH key management for both remote server access and GitHub. Adjust and dive deeper into the configurations as needed using the information provided in the upcoming sections.