Linux ssh command

The ssh command, which stands for Secure Shell, is a tool used in Linux and Unix-like operating systems for securely connecting to remote servers or devices over a network. It provides a secure encrypted connection for remote administration and secure file transfers.

The basic syntax of the ssh command is as follows:

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

Here, [options] represents the various flags and parameters you can use with the command, [user@]hostname specifies the remote server or device you want to connect to, and [command] refers to the command you want to execute on the remote system (optional).

Some commonly used options with ssh include:

  • -p: Specifies the port number for the SSH connection.
  • -i: Specifies the identity file (private key) to use for authentication.
  • -L: Sets up local port forwarding.
  • -R: Sets up remote port forwarding.
  • -X or -Y: Enables X11 forwarding for running graphical applications remotely.
  • -C: Enables compression for the SSH connection.
  • -q: Runs in quiet mode, suppressing most of the output.
  • -A: Enables agent forwarding for using local SSH keys on the remote server.

To use the ssh command, open a terminal and enter the command followed by the desired options and the hostname or IP address of the remote server. Here are a few examples:

  1. Connect to a remote server with a specific username:
ssh username@hostname
  1. Connect to a remote server using a specific port:
ssh -p port_number username@hostname
  1. Execute a command on the remote server and exit:
ssh username@hostname command
  1. Enable X11 forwarding to run graphical applications remotely:
ssh -X username@hostname

These are just a few examples, and there are many more options and use cases for the ssh command. To explore additional options and information, you can refer to the ssh command’s manual page by typing man ssh in the terminal.