SSH Snippets
# Create a private and public keyssh-keygen# Create with type and emailssh-keygen -t ed25519 -C "myemail@domain.com"# Optionally, can use flag to specific where files are created -f /path/to/key
# SSH to destination with an identity file "id_rsa_myidentity"ssh -i id_rsa_myidentity user@ip_address
Start SSH agent and add keys
Section titled “Start SSH agent and add keys”On Linux, Unix, MacOS and Windows with MSYS2/Cygwin
Section titled “On Linux, Unix, MacOS and Windows with MSYS2/Cygwin”These commands also work using msys2 and cygwin on Windows with
openssh
package installed. See Working with SSH key passphrases -
GitHub
Docs
for using a similar method with git bash on Windows.
Source: Generating a new SSH key and adding it to the ssh-agent - GitHub Docs
# Run ssh agent in backgroundeval "$(ssh-agent -s)"
# Add ssh private keyssh-add /path/to/key
# List identities and private keysssh-add -l
On Windows
Section titled “On Windows”Source: Key-based authentication in OpenSSH for Windows | Microsoft Learn
Below commands require administrative rights to start ssh-agent. For a non-administrative rights method, see the above instructions.
# By default, the ssh-agent service is disabled. Configure it to start automatically.# Run the following command as an administrator - use an administrator powershell sessionGet-Service ssh-agent | Set-Service -StartupType Automatic
# Start the service.Start-Service ssh-agent
# The following command should return a status of Running.Get-Service ssh-agent
# Load your key private files into ssh-agentssh-add $env:USERPROFILE\.ssh\id_ecdsa
Example SSH Config File using Identity File
Section titled “Example SSH Config File using Identity File”A user-specific config file is in ~/.ssh/config and system-wide configuration file for all users at /etc/ssh/sshconfig.
Host my-website.com HostName my-website.com User my-user IdentityFile ~/.ssh/id_rsa