Back to the command reference

ssh

NetworkFundamentals In real Linux

Log in to a remote machine securely

Name: ssh = Secure Shell

This command needs a real Linux system; you can practise it in real Linux mode.

Description

ssh logs into remote machines and runs commands over an encrypted connection, replacing telnet's plaintext passwords. Passwords work, keys (made with ssh-keygen) are better.

Settings for frequent hosts go in ~/.ssh/config so a short name connects. ssh also does port forwarding and jump hosts.

Syntax

ssh [OPTION]... [USER@]HOST [COMMAND]

Common options

-p PORTPort (default 22)
-i KEYFILEIdentity (private key) file
-J JUMPHOSTGo through a jump host, e.g. -J user@bastion
-L PORT:HOST:PORTLocal port forwarding
-R PORT:HOST:PORTRemote forwarding: a port on the remote machine reaches HOST:PORT from here
-D PORTA local SOCKS proxy that goes out through the remote machine
-NRun no command; only forward ports
-fGo to the background after logging in (usually with -N)
-tForce a terminal (for remote top, sudo and the like)
-o OPTIONSet a configuration option, e.g. -o StrictHostKeyChecking=no
-CCompress the data (helps on slow links)
-vVerbose, for debugging

Examples

  • $ ssh backup01

    Log in to the practice host backup01 (password: password)

    Explain
  • $ ssh -p 22 -i ~/.ssh/id_ed25519 user@backup01

    Choose the port, key and user

    Explain
  • $ ssh backup01 "df -h"

    Run one command remotely and come back

    Explain

Related