Under the explanation Linux what you don't know 7 SSH command usage

  • 2021-01-19 22:44:44
  • OfStack

A system administrator may be managing multiple servers at the same time, which may be located in different locations. It is obviously not the best way to manage them by accessing them one by one. Remote control is the most effective method.

Linux system remote management tools are about several: telnet, ssh, vnc, ssh is the most commonly used management method, using ciphertext transmission, simple and safe.

Secure Shell abbreviation SSH, Network Working Group by the IETF Network Working Group (Network Working Group), SSH is a security protocol created on the basis of the application layer and transport layer, to provide a secure transmission and use environment for computer shell.

Let's look at seven uses of SSH.

1. Basic usage

The simplest way to do this is to type ssh with no arguments and the host address, for example:


This form of login to the host, will default to the current user login. The first time you connect, SSH will confirm that the target host is real. If there is no problem, type yes.

If we want to log in to the host with the specified user name, there are two ways:

ES39en. Use the -ES40en option

ssh -l alvin

ES46en. Use the user@hostname format

ssh alvin@

Of the two methods, the second is particularly common.

2. Specify port login

The default port for SSH is 22. Most modern Linux systems have port 22 open. If you run ssh without specifying a port number, it sends requests directly through port 22.

If we don't want to log in via port 22, we can specify the port using the -p option.

ssh -p 1234

Extended topic: How to change the port number?

Simply modify /etc/ssh/ssh_config by 1 line as follows:

Port 22

3. Request compression for all data

With the -C option, all data sent or received via SSH will be compressed and will remain encrypted.

ssh -C

However, this option can be useful when the network speed is not very high, and when the network speed is very high, using compression can be inefficient, so use it depending on the situation.

4. Turn on debug mode

For some reason, we want to keep track of debugging the SSH connections we have established. The -v option parameter provided by ES95en is designed for this purpose. It can see where things go wrong.

[Alvin.Alvin-computer] ➤ ssh -v pi@
OpenSSH_7.1p2, OpenSSL 1.0.1g 7 Apr 2014
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to [] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Raspbian-10+deb9u4
debug1: match: OpenSSH_7.4p1 Raspbian-10+deb9u4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to as 'pi'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received

5. Bind the source address

If your client has more than two IP addresses, you will not be able to tell which IP is being used to connect to the SSH server. To resolve this situation, we can use the -b option to specify 1 IP address. The IP will be used as the source address to establish the connection.

[Alvin.Alvin-computer] ➤ ssh -b pi@
Linux raspberrypi 4.14.71-v7+ #1145 SMP Fri Sep 21 15:38:35 BST 2018 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Feb 24 08:52:29 2019 from

6. Execute commands remotely

If we want to execute a command on the target host, we usually do it by logging in to the target host, executing the command, and then logging out. It is certainly possible to do so, but it is troublesome.

If we only want to execute a command remotely, we can simply follow the command as follows:

[Alvin.Alvin-computer] ➤ ssh pi@ ls -l

7. Mount the remote file system

Another great SSH based tool is called sshfs. sshfs allows you to mount the file system of a remote host directly locally. It can be used in the following format:

sshfs -o idmap=user user@hostname:/home/user ~/Remote

Such as:

sshfs -o idmap=user pi@ ~/Pi

Related articles: