Command used to log in to the server over SSH

ssh hostname
Copy the code

In the command above, hostname is the hostname, which can be a domain name, an IP address, or a hostname within the LAN. If no user name is specified, the current user name of the client is used as the login user name of the remote server.

If you want to specify a user name, use the following syntax.

ssh user@hostname
Copy the code

In the above command, the user name and host name are written together, separated by @.

Specify the user name, using SSH and -l arguments

ssh -l username host
Copy the code

SSH connects to port 22 of the server by default. The -p parameter can specify other ports

ssh -p 8821 hostname
Copy the code

SSH Executes remote commands

Write the command directly after the SSH command

ssh username@hostname command
Copy the code

The preceding command causes the SSH to run command on the remote host immediately after successful login.

example

ssh [email protected] cat /etc/hosts
Copy the code

After a successful login, run the cat /etc/hosts command remotely.

SSH command line configuration item

-cParameter specifies the encryption algorithm.

$ ssh -c blowfish,3des server.example.com
# or
$ ssh -c blowfish -c 3des server.example.com
Copy the code

The above command specifies the use of the encryption algorithms blowfish or 3DES

-CParameter indicates compressed data transmission

ssh -C server.example.com
Copy the code

-dParameter Setting The level of the debugging information to be printed. The higher the value is, the more details are displayed.

SSH - d 1 foo.comCopy the code

-DParameter specifies the native Socks listening port

All requests received on the port are forwarded to the remote SSH host, also known as dynamic port forwarding

 ssh -D 1080 server
Copy the code

This command forwards all requests received by port 1080 on the local machine to the server

-fParameter Indicates that the SSH connection is running in the background

-FParameter specifies the configuration file

ssh -F /usr/local/ssh/other_config
Copy the code

The command above specifies that the configuration file other_config be used

-iParameter is used to specify the private key

The value stands for identity_file and the default value is ~/.ssh/id_dsa. Note that the corresponding public key must be stored on the server

ssh -i my-key server.example.com
Copy the code

-lParameter Specifies the account name for remote login

$ ssh -l sally server.example.com
# is equal to
$ ssh [email protected]
Copy the code

-LParameter Setting Local port forwarding

ssh  -L 9999:targetServer:80 user@remoteserver
Copy the code

Remoteserver sends all requests to port 9999 to the targetServer port 80

-mParameter specifies the algorithm used to verify data integrity

ssh -m hmac-sha1,hmac-md5 server.example.com
Copy the code

The preceding command specifies the data verification algorithm as HMAC-SHA1 or HMAC-MD5

-oParameter is used to specify a configuration command

ssh -o "Keyword Value"
Copy the code

For example, the configuration file has the following contents.

User sally
Port 220
Copy the code

Using the -o parameter, you can pass the preceding two configuration commands from the CLI.

ssh -o "User sally" -o "Port 220" server.example.com
Copy the code

When an equals sign is used, the configuration command does not need to be enclosed in quotation marks, but the equals sign cannot contain Spaces

ssh -o User=sally -o Port=220 server.example.com
Copy the code

-pParameter Specifies the server port to which the SSH client connects

ssh -p 2035 server.example.com
Copy the code

The command above connects to port 2035 of the server

-qParameter Specifies the quiet mode. No warning information is displayed

SSH -q foo.com root's password:Copy the code

The preceding command uses the -q parameter to output only the prompt for the user to enter the password

-RParameter Specifies remote port forwarding

ssh -R 9999:targetServer:902 local
Copy the code

The above command needs to be executed on the springboard server, specifying that the local computer listens on its own port 9999, and all requests sent to this port are redirected to port 902 of targetServer

-tParameter provides an interactive Shell when SSH runs a remote command directly

ssh -t server.example.com emacs
Copy the code

-vParameter Displays detailed information

ssh -v server.example.com
Copy the code

-v can be repeated several times to indicate the level of detail, such as -vv and -VVv

$ ssh -vvv server.example.com
# or
$ ssh -v -v -v server.example.com
Copy the code

The above command outputs the most detailed connection information

-VParameter Indicates the SSH client version

$SSH -v SSH: SSH Secure Shell 3.2.3 (non-commercial version) on I686-PC-Linux-GNUCopy the code

The SSH client version is SSH Secure Shell 3.2.3

-XParameter Indicates that X window forwarding is enabled

ssh -X server.example.com
Copy the code

The -1 and -2 parameters specify the SSH1 and SSH2 protocols.

ssh -2 server.example.com
Copy the code

4 -Specifies the use of IPv4, which is the default

ssh -4 server.example.com
Copy the code

- 6The IPv6 protocol is specified

ssh -6 server.example.com
Copy the code