ToolStack
KO

SSH Commands Cheatsheet

SSH connection, key generation, SCP file transfer, and port forwarding

Your data never leaves the browser — all processing is done locally 0 server requests

01

Basic Connection

  • ssh user@host

    Connect to a remote server via SSH

  • ssh -p 2222 user@host

    Connect on a specified port (default is 22)

  • ssh -i ~/.ssh/id_rsa user@host

    Connect using a specific private key file

  • ssh -v user@host

    Connect with debug output (-vvv for more detail)

  • ssh user@host "ls -la"

    Run a single command on the remote server and exit

02

Key Generation & Management

  • ssh-keygen -t ed25519 -C "comment"

    Generate an Ed25519 key pair (recommended algorithm)

  • ssh-keygen -t rsa -b 4096 -C "comment"

    Generate an RSA 4096-bit key pair

  • ssh-copy-id user@host

    Automatically register your public key on a remote server

  • cat ~/.ssh/id_ed25519.pub | ssh user@host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

    Manually register your public key on a remote server

  • ssh-keygen -R host

    Remove a host entry from known_hosts (after a key change)

03

ssh-agent & Adding Keys

  • eval "$(ssh-agent -s)"

    Start ssh-agent and set the required environment variables

  • ssh-add ~/.ssh/id_ed25519

    Add a private key to ssh-agent

  • ssh-add -l

    List keys currently loaded in ssh-agent

  • ssh-add -d ~/.ssh/id_ed25519

    Remove a specific key from ssh-agent

04

File Transfer (SCP & SFTP)

  • scp 파일 user@host:/경로/

    Upload a local file to a remote server

  • scp user@host:/경로/파일 ./로컬경로

    Download a file from a remote server to local

  • scp -r 폴더명 user@host:/경로/

    Recursively transfer an entire directory

  • scp -P 2222 파일 user@host:/경로/

    Specify the SCP port (uppercase -P)

  • sftp user@host

    Start an interactive SFTP session (use get/put to transfer files)

  • rsync -avz 폴더/ user@host:/경로/

    Efficiently sync only changed files (an alternative to scp)

05

Port Forwarding & Tunneling

  • ssh -L 8080:localhost:80 user@host

    Forward local port 8080 to remote port 80 (local forwarding)

  • ssh -R 8080:localhost:3000 user@host

    Forward remote port 8080 to local port 3000 (remote forwarding)

  • ssh -D 1080 user@host

    Create a local SOCKS5 proxy (dynamic forwarding)

  • ssh -N -f -L 8080:localhost:80 user@host

    Run port forwarding only in the background

06

Config File Setup

Writing entries in ~/.ssh/config lets you connect using simple SSH aliases

  • Host myserver HostName 1.2.3.4 User ubuntu IdentityFile ~/.ssh/id_ed25519 Port 22

    Define a server alias → connect with ssh myserver

  • Host * ServerAliveInterval 60 ServerAliveCountMax 3

    Send a keepalive packet every 60 seconds (prevents disconnects)

  • ssh myserver

    Connect using an alias defined in the config file

SSH: Secure Server Access Made Easy

SSH is the standard protocol for secure remote access and file transfer. Key-based authentication is far more secure than passwords: generate an Ed25519 key pair with ssh-keygen, register the public key with ssh-copy-id, and connect passwordlessly from then on.

The ~/.ssh/config file is a time-saver: define a Host alias with HostName, User, IdentityFile, and Port to connect with just ssh myserver. Add ServerAliveInterval 60 under Host * to keep all connections alive.

For file transfers, rsync -avz is more efficient than scp for large or repeated syncs — it only transfers changed bytes. Port forwarding turns SSH into a secure tunnel for accessing internal services without opening firewall ports.

FAQ

I get "authenticity of host can't be established" on first connect. Is this normal?
Yes, this is expected when connecting to a new host for the first time. The server's host key is not yet in your known_hosts file. Verify the server address is correct, then type yes to add it. For scripted automation, use -o StrictHostKeyChecking=no cautiously — it disables this security check.
How do I connect without a password?
Generate a key pair with ssh-keygen -t ed25519, then register the public key on the server with ssh-copy-id user@host. After that, SSH authenticates with your private key and skips the password prompt. Set IdentityFile in ~/.ssh/config for convenience.
My SSH connection keeps dropping. How do I fix it?
Add ServerAliveInterval 60 and ServerAliveCountMax 3 to ~/.ssh/config. This sends a keepalive packet every 60 seconds, preventing idle timeout disconnections. You can also adjust ClientAliveInterval on the server side.

Related Tools