SSH command usage, options, and configuration in Linux/Unix (2024)

This page is about the OpenSSH ssh command on Unix/Linux or the Mac terminal. For general information about SSH and other implementations, see the SSH protocol home page.

Practically every Unix and Linux system includes the ssh command. This command is used to start the SSH client program that enables secure connection to the SSH server on a remote machine. The ssh command is used from logging into the remote machine, transferring files between the two machines, and for executing commands on the remote machine.

Contents

SSH Command in Linux Other SSH Commands Using the Linux client Specifying a different user name Executing remote commands on the server SSH client configuration file Configuring public key authentication Configuring port forwarding SSH command line options A little history

SSH command usage, options, and configuration in Linux/Unix (1)

SSH Command in Linux

The ssh command provides a secure encrypted connection between two hosts over an insecure network. This connection can also be used for terminal access, file transfers, and for tunneling other applications. Graphical X11 applications can also be run securely over SSH from a remote location.

Other SSH Commands

There are other SSH commands besides the client ssh. Each has its own page.

Using the Linux client

Linux typically uses the OpenSSH client. The ssh command to log into a remote machine is very simple. To log in to a remote computer called sample.ssh.com, type the following command at a shell prompt:

ssh sample.ssh.com

If this is the first time you use ssh to connect to this remote machine, you will see a message like:

The authenticity of host 'sample.ssh.com' cannot be established.
DSA key fingerprint is 04:48:30:31:b0:f3:5a:9b:01:9d:b3:a7:38:e2:b1:0c.
Are you sure you want to continue connecting (yes/no)?

Type yes to continue. This will add the server to your list of known hosts (~/.ssh/known_hosts) as seen in the following message:

Warning: Permanently added 'sample.ssh.com' (DSA) to the list of known hosts.

Each server has a host key, and the above question related to verifying and saving the host key, so that next time you connect to the server, it can verify that it actually is the same server.

Once the server connection has been established, the user is authenticated. Typically, it asks for a password. For some servers, you may be required to type in a one-time password generated by a special hardware token.

Once authentication has been accepted, you will be at the shell prompt for the remote machine.

Specifying a different user name

It is also possible to use a different username at the remote machine by entering the command as:

ssh alternative-username@sample.ssh.com

The above can also be expressed with the syntax:

ssh -l alternative-username sample.ssh.com

Executing remote commands on the server

The ssh command is often also used to remotely execute commands on the remote machine without logging in to a shell prompt. The syntax for this is:

ssh hostname command

For example, to execute the command:

ls /tmp/doc 

on host sample.ssh.com, type the following command at a shell prompt:

ssh sample.ssh.com ls /tmp/doc

After authenticating to the remote server, the contents of the remote directory will be displayed, and you will return to your local shell prompt. -x Disables X11 forwarding.

SSH client configuration file

The ssh command reads its configuration from the SSH client configuration file ~/.ssh/config. For more information, see the page on SSH client configuration file.

SSH command usage, options, and configuration in Linux/Unix (2)Configuring public key authentication

To configure passwordless public key authentication, you may want to create an SSH key and set up an authorized_keys file. See the pages on ssh-keygen and ssh-copy-id for more information.

Configuring port forwarding

Command-line options can be used to set up port forwarding. Local fowarding means that a local port (at the client computer) is tunneled to an IP address and port from the server. Remote forwarding means that a remote port (at the server computer) is forwarded to a given IP address and port from the client machine. See the page on configuring port forwarding on how to configure them.

OpenSSH also supports forwarding Unix domain sockets and IP packets from a tunnel device to establish a VPN (Virtual Private Network).

SSH command line options

Some of the most important command-line options for the OpenSSH client are:

-1 Use protocol version 1 only.

-2 Use protocol version 2 only.

-4 Use IPv4 addresses only.

-6 Use IPv6 addresses only.

-A Enable forwarding of the authentication agent connection.

-a Disable forwarding of the authentication agent connection.

-C Use data compression

-c cipher_spec Selects the cipher specification for encrypting the session.

-D [bind_address:]port Dynamic application-level port forwarding. This allocates a socket to listen to port on the local side. When a connection is made to this port, the connection is forwarded over the secure channel, and the application protocol is then used to determine where to connect to from the remote machine.

-E log_file Append debug logs to log_file instead of standard error.

-F configfile Specifies a per-user configuration file. The default for the per-user configuration file is ~/.ssh/config.

-g Allows remote hosts to connect to local forwarded ports.

-i identity_file A file from which the identity key (private key) for public key authentication is read.

-J [user@]host[:port] Connect to the target host by first making a ssh connection to the pjump host[(/iam/jump-host) and then establishing a TCP forwarding to the ultimate destination from there.

-l login_name Specifies the user to log in as on the remote machine.

-p port Port to connect to on the remote host.

-q Quiet mode.

-V Display the version number.

-v Verbose mode.

-X Enables X11 forwarding.

A little history

SSH replaced several older commands and protocols in Unix and Linux the 1990s. The include telnet, rlogin, and rsh.

SSH runs at TCP/IP port 22. This is right between ftp and telnet, which are 20 years older. Read the story of how SSH got port 22.

The following video summarizes how and why SSH was originally developed.

SSH history with Tatu Ylonen

SSH command usage, options, and configuration in Linux/Unix (2024)

FAQs

What is the use of SSH command in Linux? ›

SSH Command in Linux

The ssh command provides a secure encrypted connection between two hosts over an insecure network. This connection can also be used for terminal access, file transfers, and for tunneling other applications. Graphical X11 applications can also be run securely over SSH from a remote location.

What is SSH configuration in Linux? ›

The SSH protocol creates a secure connection between two remote machines. An SSH config file helps easily configure the default values for these connections and enables efficient streamlining of SSH connections.

What is option in SSH command? ›

SSH Command Line Options
SSH OptionDescription
-VDisplays the version of ssh tool and exits.
-vPrints debugging messages for ssh connection. The verbose mode is useful when troubleshooting configuration issues.
-XUse this option to enable X11 forwarding.
-xDisable X11 forwarding.
13 more rows
Aug 25, 2019

How to use SSH command line? ›

You can start an SSH session in your command prompt by executing ssh user@machine and you will be prompted to enter your password. You can create a Windows Terminal profile that does this on startup by adding the commandline setting to a profile in your settings.json file inside the list of profile objects.

How to control Linux with SSH? ›

In the PuTTY configuration window, do the following:
  1. Go to Connection -> SSH -> Tunnels.
  2. Type in the source port number in the Source port field.
  3. Type the VNC server address and port in the Destination field.
  4. Start the SSH session as you normally would.
  5. Connect to your server with a VNC client of your choice.
Nov 23, 2023

How to do SSH configuration? ›

Procedure
  1. Open the SSH configuration file /etc/ssh/sshd_config.
  2. Disable non-admin SSH tunneling. ...
  3. Disable agent forwarding (which is enabled by default). ...
  4. Update authentication methods. ...
  5. If SSH is not going to be used for other purposes on your system, consider restricting use to an explicit list of allowed HSTS users.

Where is SSH config on Linux? ›

The ssh program on a host receives its configuration from either the command line or from configuration files ~/.ssh/config and /etc/ssh/ssh_config .

How to create SSH configuration? ›

Create SSH configurations
  1. In the Settings dialog ( Ctrl Alt 0S ) , go to Tools | SSH Configurations.
  2. In the left-hand pane that lists all the existing SSH configurations, click .
  3. Use the Visible only for this project checkbox to enable reuse of this server access configuration in other projects.
Apr 17, 2024

What is command options? ›

A command-line option or simply option (also known as a flag or switch) modifies the operation of a command; the effect is determined by the command's program. Options follow the command name on the command line, separated by spaces.

How do you use options in UNIX? ›

Most UNIX utilities require you to prefix options with a hyphen. However, this requirement is specific to the utility and not the shell. If you need to use several options, you can usually (but not always) group them into one argument that starts with a single hyphen; do not put spaces between the options.

What is option in UNIX command? ›

Linux/UNIX commands have options and/or arguments that can be typed after the basic command to further specify an action. Arguments are typically paths to files (ref. File Systems) and options assign more specific functions to the command, or add additional actions to the command.

How to check SSH status in Linux? ›

You can verify that the SSH server is running by running “ssh localhost” on the Linux side. If it asks for the key/password, the server is active: If the server is not running, you can manually start it by running “sudo service sshd start” or “sudo systemctl start sshd”.

How to check SSH connection in Linux? ›

The ss Command

Another useful utility to find SSH connections is the ss command. It's a tool that's used to investigate sockets. Something to consider when using ss is that we don't see the usernames behind the connections as we do with netstat.

How to use SSH key in Linux terminal? ›

Copy and install the public ssh key using ssh-copy-id command on a Linux or Unix server. Add yourself to sudo or wheel group admin account. Disable the password login for root account. Test your password less ssh keys login using ssh user@server-name command.

What is benefit of using SSH? ›

The main advantage of SSH is the use of encryption to ensure the secure transfer of information between the client and the server. SSH allows users to execute shell commands on a remote computer in the same way as if they were sitting in front of the physical computer.

Why is SSH key used? ›

An SSH key is an access credential for the SSH (secure shell) network protocol. This authenticated and encrypted secure network protocol is used for remote communication between machines on an unsecured open network. SSH is used for remote file transfer, network management, and remote operating system access.

Why is SSH protocol used? ›

The SSH protocol (also referred to as Secure Shell) is a method for secure remote login from one computer to another. It provides several alternative options for strong authentication, and it protects communications security and integrity with strong encryption.

Top Articles
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 6522

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.