Free Republic
Browse · Search
General/Chat
Topics · Post Article

Skip to comments.

SSH Command
Linuxize ^ | 17 December 2019 | Unknown/Staff

Posted on 12/19/2019 8:05:28 AM PST by ShadowAce

Secure Shell (SSH) is a cryptographic network protocol used for an encrypted connection between a client and a server. The ssh client creates a secure connection to the SSH server on a remote machine. The encrypted connection can be used to execute commands on the server, X11 tunneling, port forwarding, and more.

There are a number of SSH clients available both free and commercial, with OpenSSH being the most widely used client. It is available on all major platforms, including Linux, OpenBSD, Windows, macOS and others.

In this article, we will explain how to use the OpenSSH command-line client (ssh) to login to a remote machine and run commands or perform other operations.

Installing OpenSSH Client

The OpenSSH client program is called ssh and can be invoked from the terminal. The OpenSSH client package also provides other SSH utilities such as scp and sftp that are installed alongside the ssh command.

Installing OpenSSH Client on Linux

OpenSSH client is preinstalled on most Linux distributions by default. If your system doesn't have the ssh client installed, you can install it using the package manager of your distribution.

Installing OpenSSH on Ubuntu and Debian

sudo apt update
sudo apt install openssh-client

Installing OpenSSH on CentOS and Fedora

sudo dnf install openssh-clients

Installing OpenSSH Client on Windows 10

Most Windows users are using Putty to connect to a remote machine over SSH. However, the latest versions of Windows 10 include an OpenSSH client and server. Both packages can be installed via the GUI or PowerShell.

To find the exact name of the OpenSSH package, type the following command:

Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'

The command should return something like this:

Name  : OpenSSH.Client~~~~0.0.1.0
State : NotPresent
Name  : OpenSSH.Server~~~~0.0.1.0
State : NotPresent

Once you know the package name install it by running:

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

On success the output will look something like this:

Path          :
Online        : True
RestartNeeded : False

Installing OpenSSH Client on macOS

macOS ships with the OpenSSH client installed by default.

How to Use the ssh Command

The following requirements must be met to be able to login into a remote machine via SSH:

The basic syntax of the ssh command is as follows:

ssh [OPTIONS] [USER@]:HOST

To use the ssh command open your Terminal or PowerShell and type ssh followed by the remote hostname:

ssh ssh.linuxize.com

When you connect to a remote machine through SSH for the first time, you will see a message like below.

The authenticity of host 'ssh.linuxize.com (192.168.121.111)' can't be established.
ECDSA key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY.
Are you sure you want to continue connecting (yes/no)?

Each host has a unique fingerprint that is stored in the ~/.ssh/known_hosts file.

Type yes to store the remote fingerprint, and you’ll be prompted to enter your password.

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

dev@ssh.linuxize.com's password:

Once you enter the password, you will be logged into the remote machine.

When the username is not given, the ssh command uses the current system login name.

To log in as a different user, specify the username and the host in the following format:

ssh username@hostname

The username can also be specified with the -l option:

ssh -l username hostname

By default, when no port is given, the SSH client will try to connect to the remote server on port 22. On some servers, administrators are changing the default SSH port to add an extra layer of security to the server by reducing the risk of automated attacks.

To connect on a non-default port, use the -p option to specify the port:

ssh -p 5522 username@hostname

If you are experiencing authentication or connection issues, use the -v option to tell ssh to print debugging messages:

ssh -v username@hostname

To increase the level of verbosity, use -vv or -vvv.

The ssh command accepts a number of options.

For a complete list of all options read the ssh man page by typing man ssh in your terminal.

SSH Config File

If you are connecting to multiple remote systems over SSH on a daily basis, you'll find that remembering all of the remote IP addresses, different usernames, non-standard ports, and various command-line options is difficult, if not impossible.

The OpenSSH client reads the options set in the per-user configuration file (~/.ssh/config). In this file, you can store different SSH options for each remote machine you connect to.

A sample SSH config is shown below:

Host dev
    HostName dev.linuxize.com
    User mike
    Port 4422

When you invoke the ssh client by typing ssh dev the command will read the ~/.ssh/config file and use the connection details that are specified for the dev host. In this example, ssh dev is equivalent to the following:

ssh -p 4422 mike@dev.linuxize.com

For more information, check the article on SSH config file.

Public Key Authentication

The SSH protocol supports various authentication mechanisms.

The public key-based authentication mechanism allows you to log in to the remote server without having to type your password.

This method works by generating a pair of cryptographic keys that are used for authentication. The private key is stored on the client device, and the public key is transferred to each remote server that you want to log in. The remote server must be configured to accept key authentication.

If you already don't have SSH key pair on your local machine you can generate one by typing:

ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"

You will be asked to type a secure passphrase. Whether you want to use passphrase it's up to you.

Once you have your key pair, copy the public key to the remote server:

ssh-copy-id username@hostname

Enter the remote user password, and the public key will be appended to the remote user authorized_keys file.

Once the key is uploaded, you can log in to the remote server without being prompted for a password.

By setting a key-based authentication, you can simplify the login process and increase the overall server security.

Port Forwarding

SSH tunneling or SSH port forwarding is a method of creating an encrypted SSH connection between a client and a server machine through which services ports can be relayed.

SSH forwarding is useful for transporting network data of services that use an unencrypted protocol, such as VNC or FTP, accessing geo-restricted content or bypassing intermediate firewalls. Basically, you can forward any TCP port and tunnel the traffic over a secure SSH connection.

There are three types of SSH port forwarding:

Local Port Forwarding

Local port forwarding allows you to forward a connection from the client host to the SSH server host and then to the destination host port.

To create a local port forwarding pass the -L option to the ssh client:

ssh -L [LOCAL_IP:]LOCAL_PORT:DESTINATION_HOST:DESTINATION_PORT -N -f username@hostname

The -f option tells the ssh command to run in the background and -N not to execute a remote command.

Remote Port Forwarding

Remote port forwarding is the opposite of local port forwarding. It forwards a port from the server host to the client host and then to the destination host port.

The -L option tells ssh to create a remote port forwarding:

ssh -R [REMOTE:]REMOTE_PORT:DESTINATION:DESTINATION_PORT -N -f username@hostname

Dynamic Port Forwarding

Dynamic port forwarding creates a SOCKS proxy server that allows communication across a range of ports.

To create a dynamic port forwarding (SOCKS) pass the -D option to the ssh client:

ssh -R [LOCAL_IP:]LOCAL_PORT  -N -f username@hostname

For more detailed information and step-by-step instruction, check the article on How to Set up SSH Tunneling (Port Forwarding) .


TOPICS: Computers/Internet
KEYWORDS: linux; shell; windows
Navigation: use the links below to view more comments.
first 1-2021-28 next last

1 posted on 12/19/2019 8:05:28 AM PST by ShadowAce
[ Post Reply | Private Reply | View Replies]

To: rdb3; Calvinist_Dark_Lord; JosephW; Only1choice____Freedom; martin_fierro; Still Thinking; ...

Tech Ping


2 posted on 12/19/2019 8:06:22 AM PST by ShadowAce (Linux - The Ultimate Windows Service Pack)
[ Post Reply | Private Reply | To 1 | View Replies]

To: ShadowAce

Rule 1 - never use passwords. Don’t even think about it. Use the public key encryption option.


3 posted on 12/19/2019 8:12:18 AM PST by glorgau
[ Post Reply | Private Reply | To 1 | View Replies]

To: ShadowAce

In layman terms what is/are the benefits of using SSH?


4 posted on 12/19/2019 8:14:01 AM PST by Robert DeLong
[ Post Reply | Private Reply | To 1 | View Replies]

To: Robert DeLong
I'll give you my ssh application--

I manage a couple of thousand linux servers. They all are located in the datacenter several floors below me. In order to manage any single one, I need to log in.

With SSH, I can do that from my desk, without ever having to actually go the physical server.

5 posted on 12/19/2019 8:16:03 AM PST by ShadowAce (Linux - The Ultimate Windows Service Pack)
[ Post Reply | Private Reply | To 4 | View Replies]

To: ShadowAce

So this is not something that a plain user would find a real reason to use it, is that an accurate statement? Or is there a reason the average computer user would see a need for this knowledge? 8>)


6 posted on 12/19/2019 8:24:16 AM PST by Robert DeLong
[ Post Reply | Private Reply | To 5 | View Replies]

To: Robert DeLong
Not the average desktop user, no.

However, I have posted threads aimed at some of the IT professionals among us in the past. This is one of those.

7 posted on 12/19/2019 8:25:15 AM PST by ShadowAce (Linux - The Ultimate Windows Service Pack)
[ Post Reply | Private Reply | To 6 | View Replies]

To: ShadowAce

Groovy! I use Putty quite a bit, so it’s nice to have another option.


8 posted on 12/19/2019 8:37:27 AM PST by Edward Teach
[ Post Reply | Private Reply | To 1 | View Replies]

To: ShadowAce

In addition to PKI encrypted communications for login sessions there is the scp command which enables you to copy entire file hierarchies from one machine to others with a single command and the use of shell meta characters.

There is also the ability to create encrypted “tunnels” for data stream end points with ssh and so much more.

https://linux.die.net/man/1/ssh


9 posted on 12/19/2019 8:49:40 AM PST by lurked_for_a_decade (Imagination is more important than knowledge! ( e_uid == 0 ) != ( e_uid = 0 ). I Read kernel code.)
[ Post Reply | Private Reply | To 5 | View Replies]

To: ShadowAce

One of the best things Microsoft did in Windows 10 was include the SSH client, and make the server available for installation. Finally, Windows stumbles into the 1990’s.


10 posted on 12/19/2019 9:28:09 AM PST by dayglored ("Listen. Strange women lying in ponds distributing swords is no basis for a system of government."`)
[ Post Reply | Private Reply | To 1 | View Replies]

To: ShadowAce

I used to use port forwarding a lot, mostly to get around firewalls and stuff. It was very cool. Still use SSH daily. It’s a powerful tool. I’d recommend changing that command above to generate a key to use DSA. RSA is pretty much deprecated these days.


11 posted on 12/19/2019 10:09:11 AM PST by zeugma (I sure wish I lived in a country where the rule of law actually applied to those in power.)
[ Post Reply | Private Reply | To 1 | View Replies]

To: lurked_for_a_decade
In addition to PKI encrypted communications for login sessions there is the scp command which enables you to copy entire file hierarchies from one machine to others with a single command and the use of shell meta characters.

Rsync is insanely powerful and efficient. Love, love love it. Makes my life easier when I need to replicate data from one host to another. Since it uses ssh, it's secure, and can also compress to reduce transmission times, among other things.

12 posted on 12/19/2019 10:12:07 AM PST by zeugma (I sure wish I lived in a country where the rule of law actually applied to those in power.)
[ Post Reply | Private Reply | To 9 | View Replies]

To: ShadowAce

Thank you for this. I couldn’t figure out how to change the username when using powershell to SSH into my Cisco equipment. I just wanted to use radius auth.


13 posted on 12/19/2019 10:41:19 AM PST by miliantnutcase
[ Post Reply | Private Reply | To 1 | View Replies]

To: zeugma

Yup. Good stuff.


14 posted on 12/19/2019 10:55:27 AM PST by lurked_for_a_decade (Imagination is more important than knowledge! ( e_uid == 0 ) != ( e_uid = 0 ). I Read kernel code.)
[ Post Reply | Private Reply | To 12 | View Replies]

To: ShadowAce
Many thanks. Something to read during my surgery recovery.

Merry Christmas!

(Hmmm ... any chance you could sneak a F@H client onto a few thousand of those servers? Not like they are doing anything except waiting for the next cryptocurrency hijack ... not that anyone could get past your superb security :)

15 posted on 12/19/2019 1:00:51 PM PST by texas booster (Join FreeRepublic's Folding@Home team (Team # 36120) Cure Alzheimer's!)
[ Post Reply | Private Reply | To 1 | View Replies]

To: ShadowAce

SecureCRT allows you to change the background of a terminal session which is nice if you have multiple servers and you don’t want to confuse them


16 posted on 12/19/2019 1:02:44 PM PST by AppyPappy (How many fingers am I holding up, Winston?)
[ Post Reply | Private Reply | To 1 | View Replies]

To: Robert DeLong; ShadowAce

Ace scares the heck out of the average user with these. lol

I appreciate them very much though, I have learned quite a bit from them.


17 posted on 12/19/2019 4:40:04 PM PST by Openurmind (The ultimate test of a moral society is the kind of world it leaves to its children. ~ D. Bonhoeffer)
[ Post Reply | Private Reply | To 6 | View Replies]

To: Openurmind

It doesn’t scare me, I was just wondering if there was ever a need for just plain old users of computers, or even someone like me who is an old mainframe person, what it might be used for if we were not PC oriented. I mean I know PC’s better than most perhaps but I was trying to figure out how I might use the knowledge. 8>)


18 posted on 12/19/2019 5:45:34 PM PST by Robert DeLong
[ Post Reply | Private Reply | To 17 | View Replies]

To: Robert DeLong
mainframe person

The mainframe is back, sort of, but it's called the cloud now. You'd use ssh to connect to the cloud server's Linux command prompt, and it's also the gold standard for secure file transfers. It's not flashy software but it's stable and high quality with very few bugs. It's a must learn for cloud computing.

19 posted on 12/19/2019 6:49:32 PM PST by Reeses (A journey of a thousand miles begins with a government pat down.)
[ Post Reply | Private Reply | To 18 | View Replies]

To: Reeses
I'm finishing up my last contract that I have been on for 19 years. After we are through in June of 2020 it's retirement time for me. 8>) But we do use FTPS for our file transfer as we don't do cloud processing, but we have racks & racks of servers. As I retire the mainframe, which is has an MVS OS built on a Unix platform, with FLEX ES as a communication between the MVS OS and Unix. So it operates and has the feel of a mainframe but looks nothing like the mainframe of old, will be retired too. I think it has a value of about 80.00 anymore. IBM no longer supports it and parts are becoming impossible to find. 8>)

Thanks for the info though. 8>)

20 posted on 12/19/2019 7:56:07 PM PST by Robert DeLong
[ Post Reply | Private Reply | To 19 | View Replies]


Navigation: use the links below to view more comments.
first 1-2021-28 next last

Disclaimer: Opinions posted on Free Republic are those of the individual posters and do not necessarily represent the opinion of Free Republic or its management. All materials posted herein are protected by copyright law and the exemption for fair use of copyrighted works.

Free Republic
Browse · Search
General/Chat
Topics · Post Article

FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson