SSH
Make sure ssh-agent
starts automatically and keys persist across reboots.
# Add these lines to ~/.bashrc
eval "$(ssh-agent -s)"
ssh-add -k ~/.ssh/*
# Check keys added to ssh-agent
ssh-add -l
ssh-add -L
SSH into a host machine:
# -i = pass in a private key (identity) file.
# IP = ip of the host machine
ssh -i ~/.ssh/id_rsa [email protected]
# Specify port
ssh <user>@<hostname> -p 8090
Kill a frozen SSH terminal:
# Key sequence = Enter, shift + ~, period
Copy file from remote to local machine desktop folder:
scp [email protected]:~/files/test.txt ./Desktop
Run bash commands on remote machine over SSH:
ssh [email protected] "ls -la ~/files"
ssh [email protected] "ls -la ~/files; cd /; ifconfig" # Multiple commands.
Adding SSH keys:
# Start SSH agent. This wipes all existing keys from the agent.
eval "$(ssh-agent -s)"
# Add the key.
ssh-add ~/.ssh/id_ed25519
# List existing keys registered with the agent.
ssh-add -l
Generate Public SSH Key from Private Key:
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
Last updated