Arshad Mehmood

Search the blog

    Today I Learned

    SSH connection basics: password, keys, and parameters

    ssh

    Basic SSH syntax: ssh [options] [user@]hostname

    Password authentication

    ssh user@hostname
    # Prompts for password

    Key-based authentication

    Use a specific private key:

    ssh -i ~/.ssh/id_rsa user@hostname

    With custom key location:

    ssh -i /path/to/private/key user@hostname

    Common key paths:

    • ~/.ssh/id_rsa — RSA key
    • ~/.ssh/id_ed25519 — Ed25519 key (recommended)
    • ~/.ssh/id_ecdsa — ECDSA key

    Useful parameters

    OptionPurpose
    -p portCustom SSH port (default 22)
    -i keyfileSpecify private key file
    -vVerbose output (debug connection issues)
    -vv or -vvvMore verbose
    -XEnable X11 forwarding
    -L local:remoteLocal port forwarding
    -R remote:localRemote port forwarding
    -NDon’t open shell (useful with port forwarding)
    -fRun in background
    -tForce pseudo-terminal allocation

    Examples

    Connect on custom port with specific key:

    ssh -i ~/.ssh/id_ed25519 -p 2222 user@hostname

    Run remote command and exit (no shell):

    ssh user@hostname "ls -la /tmp"

    Port forwarding (local):

    ssh -L 8080:localhost:3000 user@hostname -N -f
    # Maps localhost:8080 → remote:3000

    Verbose debugging:

    ssh -vvv user@hostname

    SSH key best practices

    • Use Ed25519 keys (ssh-keygen -t ed25519)
    • Protect with passphrase
    • Store in ~/.ssh/ with restricted permissions (chmod 600)
    • Use SSH agent for convenience