Install Private Key (SSH)
Here are step-by-step instructions on how to store an SSH private key securely once generated on both Windows and Mac systems:
Windows
-
Default Location
- By default, SSH private keys are saved in your user profile directory under:
C:\Users\<your_username>\.ssh\ - The private key file is usually named
id_rsaor similar.
- By default, SSH private keys are saved in your user profile directory under:
-
Set File Permissions
- Ensure only your user account has access to the private key file:
- Right-click the private key file > Properties > Security tab.
- Remove access for any other users or groups except yourself.
- Ensure only your user account has access to the private key file:
-
Use SSH-Agent for Secure Key Storage
- Open PowerShell as Administrator.
- Enable and start the ssh-agent service:
Get-Service ssh-agent | Set-Service -StartupType Automatic Start-Service ssh-agent - Add your private key to ssh-agent to avoid typing your passphrase every time:
ssh-add $env:USERPROFILE\.ssh\id_rsa - The ssh-agent stores your private keys encrypted, protected by your Windows user credentials.
-
Backup Private Key Securely
- Copy the private key file to an encrypted external drive or secure password manager.
- Avoid storing private keys in shared or non-encrypted folders.
- Do NOT share the private key.
Mac (macOS)
-
Default Location
- Private keys are stored in the hidden
.sshfolder in your home directory:~/.ssh/id_rsa - Use
ls -la ~/.sshin Terminal to view.
- Private keys are stored in the hidden
-
Set Proper File Permissions
- Ensure your private key file is readable only by you:
chmod 600 ~/.ssh/id_rsa
- Ensure your private key file is readable only by you:
-
Add SSH Key to ssh-agent
- Start the ssh-agent:
eval "$(ssh-agent -s)" - Add your private key with:
ssh-add -K ~/.ssh/id_rsa - This stores your key securely in the macOS keychain.
- Start the ssh-agent:
-
Backup Private Key Safely
- Store a copy on an encrypted USB drive or a password manager like 1Password.
- Never upload your private key unencrypted to cloud storage.
- Keep backups separate from your main machine to avoid loss.
Security best practices:
- Always protect your private key with a strong passphrase when generating it.
- Keep private key files with strict permissions so only your user account can read them.
- Use ssh-agent to manage keys in memory instead of repeatedly entering passwords or exposing keys.
- Backup private keys securely and do not share your private keys with anyone.