Advertisement

SSH Connection

Connect to remote host.

ssh user@hostname
ssh -p 2222 user@hostname
ssh -i ~/.ssh/key.pem user@hostname
ssh user@hostname command

Generate SSH Key

Create SSH key pair.

ssh-keygen
ssh-keygen -t rsa -b 4096
ssh-keygen -t ed25519
ssh-keygen -t rsa -C "email@example.com"

Copy Public Key

Copy key to remote server.

ssh-copy-id user@hostname
ssh-copy-id -i ~/.ssh/id_rsa.pub user@hostname
Advertisement

SCP - Secure Copy

Copy files securely.

scp file.txt user@host:/path/
scp user@host:/path/file.txt ./
scp -r directory/ user@host:/path/
scp -P 2222 file.txt user@host:/path/

SSH Config

Create ~/.ssh/config file.

Host myserver
    HostName 192.168.1.100
    User username
    Port 22
    IdentityFile ~/.ssh/key.pem

# Connect using:
ssh myserver

Port Forwarding

Forward ports through SSH.

ssh -L 8080:localhost:80 user@host
ssh -R 8080:localhost:80 user@host
ssh -D 1080 user@host

SSH Agent

Manage SSH keys.

eval $(ssh-agent)
ssh-add ~/.ssh/id_rsa
ssh-add -l
ssh-add -D
Last updated: January 2026
Advertisement