Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux ssh Command

Linux ssh Command

Linux Command Reference Linux Command Reference

The ssh command connects to a remote host over the SSH protocol for remote login and command execution; it encrypts all communication in the session, ensuring the security of data transmission.

SSH (Secure Shell) is an encrypted protocol used for remote login and other network services. SSH provides a secure communication channel to protect the confidentiality and integrity of data.

Syntax


ssh [options] [user@]hostname [command]

Parameter Description

Common options

Example

Basic Usage

Connect to a remote host:


ssh user@hostname

Example:

ssh test@runoob.com

Connect on a specified port:


ssh -p 2222 user@hostname

Example:


ssh -p 2222 test@runoob.com

Using an identity file:


ssh -i /path/to/private_key user@hostname

Example:


ssh -i ~/.ssh/id_rsa test@runoob.com

Execute a command on the remote host:


ssh user@hostname command

Example:


ssh test@runoob.com ls -la

Verbose mode:


ssh -v user@hostname

Example:


ssh -v test@runoob.com

Enable compression:


ssh -C user@hostname

Example:

ssh -C test@runoob.com

Run in the background without executing a command:


ssh -f -N user@hostname

Example:


ssh -f -N test@runoob.com

Port forwarding

Local port forwarding:


ssh -L local_port:remote_host:remote_port user@hostname

Example:


ssh -L 8080:localhost:80 test@runoob.com

Remote port forwarding:


ssh -R remote_port:local_host:local_port user@hostname

Example:


ssh -R 8080:localhost:80 test@runoob.com

Dynamic port forwarding:


ssh -D [bind_address:]port user@hostname

Example:


ssh -D 1080 test@runoob.com

Advanced usage

Configuration file

The SSH client configuration file is located at ~/.ssh/config, where you can set commonly used options.

Example:

Host example
    HostName example.com
    User john
    Port 2222
    IdentityFile ~/.ssh/id_rsa

To use it, simply:

ssh example

SSH agent forwarding

Enable agent forwarding:


ssh -A user@hostname

Example:


ssh -A test@runoob.com

X11 forwarding

Enable X11 forwarding:


ssh -X user@hostname

Example:


ssh -X test@runoob.com

Linux Command Reference Linux Command Reference