---
title: SSH command usage, options, and configuration in Linux/Unix
description: Learn how to use ssh commands, what are some of the options, and how to configure them in Linux/Unix.
---

[Academy ](https://www.ssh.com/academy)

# [SSH command usage, options, and configuration in Linux/Unix](https://www.ssh.com/academy/ssh/command)

 Written by [Admin](https://www.ssh.com/academy/author/admin) | Sep 24, 2019 4:00:00 AM

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](https://www.ssh.com/academy/ssh).

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](https://www.ssh.com/academy/ssh/command?hs_amp=true#ssh-command-in-linux) [Other SSH Commands](https://www.ssh.com/academy/ssh/command?hs_amp=true#other-ssh-commands) [Using the Linux client](https://www.ssh.com/academy/ssh/command?hs_amp=true#using-the-linux-client) [Specifying a different user name](https://www.ssh.com/academy/ssh/command?hs_amp=true#specifying-a-different-user-name) [Executing remote commands on the server](https://www.ssh.com/academy/ssh/command?hs_amp=true#executing-remote-commands-on-the-server) [SSH client configuration file](https://www.ssh.com/academy/ssh/command?hs_amp=true#ssh-client-configuration-file) [Configuring public key authentication](https://www.ssh.com/academy/ssh/command?hs_amp=true#configuring-public-key-authentication) [Configuring port forwarding](https://www.ssh.com/academy/ssh/command?hs_amp=true#configuring-port-forwarding) [SSH command line options](https://www.ssh.com/academy/ssh/command?hs_amp=true#ssh-command-line-options) [A little history](https://www.ssh.com/academy/ssh/command?hs_amp=true#a-little-history)

## 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.

- [ssh-keygen](https://www.ssh.com/ssh/keygen) - creates a key pair for public key authentication
- [ssh-copy-id](https://www.ssh.com/academy/ssh/copy-id) - configures a public key as authorized on a server
- [ssh-agent](https://www.ssh.com/academy/ssh/agent) - agent to hold private key for single sign-on
- [ssh-add](https://www.ssh.com/academy/ssh/add-command) - tool to add a key to the agent
- [scp](https://www.ssh.com/academy/ssh/scp) - file transfer client with RCP-like command interface
- [sftp](https://www.ssh.com/academy/ssh/sftp-ssh-file-transfer-protocol) - file transfer client with FTP-like command interface
- [sshd](https://www.ssh.com/academy/ssh/sshd) - OpenSSH server

## Using the Linux client

Linux typically uses the [OpenSSH](https://www.ssh.com/academy/ssh/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](https://www.ssh.com/academy/ssh/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](https://www.ssh.com/academy/ssh/config).

## Configuring public key authentication

To configure passwordless [public key authentication](https://www.ssh.com/academy/ssh/public-key-authentication), you may want to create an [SSH key](https://www.ssh.com/academy/ssh-keys) and set up an [authorized_keys](https://www.ssh.com/academy/ssh/authorized-keys-file) file. See the pages on [ssh-keygen](https://www.ssh.com/academy/ssh/keygen) and [ssh-copy-id](https://www.ssh.com/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](https://www.ssh.com/academy/ssh/tunneling-example) 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](https://www.ssh.com/academy/ssh/identity-key) (private key) for [public key authentication](https://www.ssh.com/ssh/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](https://www.ssh.com/ssh/tunneling/example) 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](https://www.ssh.com/academy/ssh/telnet), [rlogin](https://www.ssh.com/academy/ssh/rlogin), and [rsh](https://www.ssh.com/academy/ssh/rsh).

SSH runs at TCP/IP port 22. This is right between [ftp](https://www.ssh.com/ssh/telnet) and telnet, which are 20 years older. Read the story of [how SSH got port 22](https://www.ssh.com/academy/ssh/port).

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

[SSH history with Tatu Ylonen](https://www.youtube.com/watch?v=OHBdKM7s5V4)

[View full post](https://www.ssh.com/academy/ssh/command)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Admin"
  },
  "dateModified" : "2025-04-30T12:04:37.102Z",
  "datePublished" : "2019-09-24T04:00:00Z",
  "headline" : "SSH Command - Usage, Options, Configuration",
  "image" : {
    "@type" : "ImageObject",
    "height" : 60,
    "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
    "width" : 60
  },
  "mainEntityOfPage" : "https://www.ssh.com/academy/ssh/command",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Academy"
  }
}
```