SSH
Table of Contents
Set up passwordless SSH
- Start the
ssh-agentin the backgroundeval "$(ssh-agent -s)" - Generate new SSH key
ssh-keygen -C "your_email@example.com" - Add
SSH keyto the ssh-agentssh-add {path/to/SSH_key) - Copy
ssh-keyto the remote serverssh-copy-id remote_username@server_ip_address - Begin
sshto the remote serverssh remote_username@server_ip_address
Set up SSH on Github
- Generate new SSH key
ssh-keygen -C "your_email@example.com" - (Optional) Set personalized filename for
SSH_key> Enter a file in which to save the key (/Users/you/.ssh/id_ed25519): [Press enter] - Start the
ssh-agentin the backgroundeval "$(ssh-agent -s)" - Add
SSH keyto the ssh-agentssh-add {path/to/SSH_key) - Copy content of
SSH_key.pubto your Github account - Test your SSH connection with Github
ssh -T git@github.com
SSH activation script
#!/usr/bin/bash
# SSH credentials
SSH_KEY=$HOME/.ssh/github
# Activation script
eval "$(ssh-agent -s)"
ssh-add $SSH_KEY
echo "GitHub credentials activated!"
Start ssh-agent automatically
- Append
~/.bashrcfile with the following content.# Start ssh-agent if it's not already running if [ -z "$SSH_AUTH_SOCK" ]; then eval "$(ssh-agent -s)" fi - You might also want to add your
ssh-keyautomatically. Just append your key in the~/.bashrcfile.# Add keys to ssh-agent SSH_KEYS_TO_ADD=( "$HOME/.ssh/id_rsa" "$HOME/.ssh/id_ed25519" # Add more key paths here, one per line # "$HOME/.ssh/my_other_key" ) for key_path in "${SSH_KEYS_TO_ADD[@]}"; do if [ -f "$key_path" ]; then echo "Adding key: $key_path" ssh-add "$key_path" || echo "Failed to add key: $key_path (check passphrase or file permissions)" else echo "Warning: Private key file not found: $key_path" fi done