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 [email protected]

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

SSH command usage, options, and configuration in Linux/Unix? ›

The ssh command is used to securely log into a remote machine and execute commands on that machine. The basic syntax of the command is “ssh user@host”, where user is the username on the remote machine and host is the address or hostname of the remote machine.

How to use SSH command in Unix? ›

The ssh command is used to securely log into a remote machine and execute commands on that machine. The basic syntax of the command is “ssh user@host”, where user is the username on the remote machine and host is the address or hostname of the remote machine.

How to SSH configuration in Linux? ›

  1. Step1: Install and enable SSH Server. ...
  2. Step2: Enable SSH Protocol Version 2. ...
  3. Step 3: Customize the default SSH port (22) ...
  4. Step4: Disable root login (SSH) ...
  5. Step 5: Use ssh keys (Public and Private) ...
  6. Step 6: Disable X11 Forwarding. ...
  7. Step 7: Disable Empty Passwords. ...
  8. Step 8: Set Max Authentication Attempts.
Mar 17, 2023

What is the usage SSH 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.

How to use SSH on Linux? ›

For Linux
  1. Connect via SSH Command. Open a terminal and enter the following command: ssh @ . For example, if the IP address is 192.168. ...
  2. Enter Yes to Continue. When prompted with a warning message that says "The authenticity of host 'xxx' can't be established", enter "yes" to continue with the connection.

How to setup SSH in Unix? ›

Procedure
  1. Generate a new SSH key for WebSphere Automation by using the ssh-keygen command. $ ssh-keygen -f ~/.ssh/wsa Generating public/private rsa key pair. ...
  2. Copy the public key to each server by using the ssh-copy-id command. ...
  3. Validate that you can use SSH to communicate with that server.

How to run SSH command? ›

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 do I find my SSH configuration? ›

The default location of a user-specific config file is in ~/. ssh/config, whereas the system-wide configuration file for all users is in /etc/ssh/ssh_config.

How to change SSH configuration? ›

Changing the SSH Port
  1. Backup the Configuration File. Before making any changes, it's always a good practice to back up your SSH configuration file.
  2. Edit the SSH Configuration File. ...
  3. Sample Output:
  4. Locate the Port Directive. ...
  5. Change the Port Number. ...
  6. Save and Close the File. ...
  7. Adjust Firewall Rules. ...
  8. Restart the SSH Service.
Sep 6, 2023

How to check if SSH is enabled 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”.

What is SSH usage? ›

SSH or Secure Shell is a network communication protocol that enables two computers to communicate (c.f http or hypertext transfer protocol, which is the protocol used to transfer hypertext such as web pages) and share data.

How to run SSH service on Linux? ›

Linux start sshd command
  1. Open the terminal application.
  2. You must log in as root.
  3. Use the following commands to start the sshd service: /etc/init.d/sshd start. OR (for modern Linux distro with systemd) ...
  4. In some cases, the actual script name is different. For example, it is ssh.service on a Debian/Ubuntu Linux.
Mar 31, 2024

How to connect to a server using 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

What is the SSH command for Linux? ›

To use the SSH command in Linux, you typically use the format ssh username@hostname . This command allows you to establish a secure shell connection with a remote server. In this example, we're using the SSH command to connect to a remote server with the IP address 192.168. 1.1 as the user 'user'.

How to remote Linux using SSH? ›

Connect to a Linux server via SSH
  1. Open the list of your servers and click on the one you need. Click the Instructions button. ...
  2. Open a terminal (for Linux) or a command line (for Windows) on your computer. Enter the command: ...
  3. The connection will prompt you for a password. Enter the password from the instructions.

How does SSH work step by step? ›

There are two stages to establishing a connection – first, both the systems must agree upon encryption standards to protect future communications, and second, the user must authenticate themselves. If the credentials match, then the user is granted SSH access.

How to use SSH key command? ›

For Windows 10 & 11
  1. Press the Windows key or open up the Start Menu. Type “cmd”.
  2. Under “Best Match”, click “Command Prompt”.
  3. In the command prompt, use the ssh-keygen command: ...
  4. The system will now generate the key pair and display the key fingerprint and a randomart image. ...
  5. Open your file explorer.

How do I start SSH on Linux? ›

Linux start sshd command
  1. Open the terminal application.
  2. You must log in as root.
  3. Use the following commands to start the sshd service: /etc/init.d/sshd start. OR (for modern Linux distro with systemd) ...
  4. In some cases, the actual script name is different. For example, it is ssh.service on a Debian/Ubuntu Linux.
Mar 31, 2024

How to use SSH command in PuTTY? ›

SSH (Secure Shell) with Putty
  1. Save it on the Desktop.
  2. Double click putty on the Desktop.
  3. In the Host Name (or IP address) field, type the remote system you intend to connect to (smpserv.hku.hk in this example).
  4. Select SSH under connection type.

How to use SSH for beginners? ›

To authenticate using SSH keys, a user must have an SSH key pair on their local computer. On the remote server, the public key must be copied to a file within the user's home directory at ~/. ssh/authorized_keys . This file contains a list of public keys, one-per-line, that are authorized to log into this account.

Top Articles
DePIN: Decentralized Physical Infrastructure - A Potential Web3 Pillar for the Bull Run
Best Hardship Loans for Financial Setbacks | The Motley Fool
This website is unavailable in your location. – WSB-TV Channel 2 - Atlanta
His Lost Lycan Luna Chapter 5
Jonathon Kinchen Net Worth
Shorthand: The Write Way to Speed Up Communication
877-668-5260 | 18776685260 - Robocaller Warning!
Dr Lisa Jones Dvm Married
123 Movies Black Adam
Fallout 4 Pipboy Upgrades
Progressbook Brunswick
New Mexico Craigslist Cars And Trucks - By Owner
Persona 4 Golden Taotie Fusion Calculator
Binghamton Ny Cars Craigslist
5 high school volleyball stars of the week: Sept. 17 edition
Willam Belli's Husband
Forum Phun Extra
Nhl Tankathon Mock Draft
Air Quality Index Endicott Ny
[PDF] PDF - Education Update - Free Download PDF
Sec Baseball Tournament Score
Surplus property Definition: 397 Samples | Law Insider
Reicks View Farms Grain Bids
Wiseloan Login
Wolfwalkers 123Movies
Ordensfrau: Der Tod ist die Geburt in ein Leben bei Gott
Craigs List Jax Fl
Kleinerer: in Sinntal | markt.de
Laveen Modern Dentistry And Orthodontics Laveen Village Az
Human Unitec International Inc (HMNU) Stock Price History Chart & Technical Analysis Graph - TipRanks.com
Capital Hall 6 Base Layout
1987 Monte Carlo Ss For Sale Craigslist
2008 Chevrolet Corvette for sale - Houston, TX - craigslist
Aliciabibs
Skyrim:Elder Knowledge - The Unofficial Elder Scrolls Pages (UESP)
10 games with New Game Plus modes so good you simply have to play them twice
Michael Jordan: A timeline of the NBA legend
One Main Branch Locator
Flags Half Staff Today Wisconsin
Sept Month Weather
Ferguson Employee Pipeline
Jack In The Box Menu 2022
Wunderground Orlando
Shoecarnival Com Careers
Busted Newspaper Mcpherson Kansas
Walgreens On Secor And Alexis
Arcanis Secret Santa
Identogo Manahawkin
Diamond Desires Nyc
18443168434
Blippi Park Carlsbad
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 6160

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.