Skip to content

Instantly share code, notes, and snippets.

@rferreiraperez
Created July 30, 2024 09:04
Show Gist options
  • Save rferreiraperez/9d61e41fb6d7368f20be9be06db3d5b5 to your computer and use it in GitHub Desktop.
Save rferreiraperez/9d61e41fb6d7368f20be9be06db3d5b5 to your computer and use it in GitHub Desktop.

SSH

Check Existing SSH Keys

ls -al ~/.ssh

If you receive an error indicating that ~/.ssh does not exist, you do not have an SSH key pair at the default location.

Generate a New SSH Key

ssh-keygen -t ed25519 -C "[email protected]"

If you are using a legacy system that does not support the Ed25519 algorithm, use:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Add Your SSH Key to the SSH Agent

Start the SSH agent in the background.

eval "$(ssh-agent -s)"

Add your SSH private key to the SSH agent.

ssh-add ~/.ssh/<ssh_key>

Remove a Remote Host from the "known_hosts" File

ssh-keygen -f ~/.ssh/known_hosts -R <ip>

Copy SSH Key to Remote Host

ssh-copy-id <user>@<host>

Connect to a Remote Host

ssh <user>@<host>

SSH Tunnel (Port Forwarding)

Local Port Forwarding

ssh -L <local_port>:<remote_host>:<remote_port> <user>@<host>

Remote Port Forwarding

ssh -R <remote_port>:<local_host>:<local_port> <user>@<host>

Execute a Command on a Remote Host

ssh <user>@<host> '<command>'

Check SSH Connection

ssh -T <user>@<host>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment