Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the tips for using the SSH command?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the use of SSH command tips, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.

SSH is the basic tool for remote connection under Linux. The common use of SSH is to log in. SSH command is an artifact to complete remote operations. With it, we can automate a lot of remote operations.

SSH command details syntax ssh (option) (parameter) option-1: force the use of ssh protocol version 1 mai 2: force the use of ssh protocol version 2 mae 4: force the use of IPv4 address;-6: force the use of IPv6 address;-A: enable authentication agent connection forwarding function;-a: turn off authentication agent connection forwarding function;-b: use the local specified address as the source ip address of the corresponding connection -C: request compression of all data;-F: specify configuration file for ssh instruction;-f: execute ssh instruction in the background;-g: allow remote host to connect to host forwarding port;-I: specify identity file;-l: specify login user name for connecting remote server;-N: do not execute remote instruction;-o: specify configuration option;-p: specify port on remote server;-Q: silent mode -X: enable X11 forwarding function;-x: disable X11 forwarding function;-y: enable trust X11 forwarding function. Parameter remote host: specifies the remote ssh server to connect to; instruction: the instruction to be executed on the remote ssh server. SSH connection usage

Grammar looks rigid and cumbersome, but it doesn't need that much. This is the only thing used in the habit.

Ssh name@server-ip

Or

Ssh server-ip-l name

Both of the above methods can log in to the server remotely. Server-ip represents the IP address of the remote server, and name represents the user name of the SSH login to the remote server, usually root.

If the port of the remote server is something else, add the-p parameter after it.

Ssh name@server-ip-p 12345

If the connection is successful, the terminal will be prompted to continue to enter the user password, just enter it.

SSH uses public key to log in without secret

There are two ways to verify when logging in with SSH

Password-based security authentication, which requires the user to enter a password every time he logs in to the server, and the login is successful after the server-side authentication is passed. In the security authentication based on the key, the public key of the client is saved in advance on the server side. When logging in, the server side will use the public key for authentication. If the authentication is successful, the user does not need to enter the password to complete the login.

To avoid the repetitive work of entering a password every time, we can choose to log in remotely using the public key.

The locally generated key is used to ssh-keygen the terminal and then enter all the way. Enter is the default setting for saving the key pair and opening the password. After execution, you will be prompted that the private key files and public key files named id_rsa and id_rsa.pub are in the / home/user/.ssh directory.

Then upload the public key to the remote server

Ssh-copy-id root@server-ip

Server-ip is the IP address of the remote server. Then enter the password as prompted. When you see the terminal display

Number of key (s) added: 1Now try logging into the machine, with: "ssh 'root@remoteserver" and check to make sure that only the key (s) you wanted were added.

Indicates that the upload is successful, and then you can log in to the remote server directly using the "ssh root@server-ip" command without the need for a password

Set alias login to the remote server

Even if you set up secret-free login, the server-ip that you need to bring after the SSH command is troublesome enough. After a few years, the IPV6 address will be popularized, and the ssh login will be desperate. We can further exempt the IP address of the server by configuring the server alias.

Create a new config file in the / home/user/.ssh/ directory as follows:

Host hostnameHostName server-ipUser rootIdentitiesOnly yes

Just save the return place. Note that the hotname in the first line is the alias you set for the server, whatever you want. The second line server-ip is replaced by the IP of your remote server. Don't copy it foolishly.

Then you can execute the "ssh hostname" command (change the hostname to the alias you set) and log in to the remote server happily.

If an error is made with the words "Bad owner or permissions on / home/root/.ssh/config", it is a matter of permissions.

Execute the config file

Chmod 600 config

Copy command for scp. It can also be used directly. Scp is a secure remote file copy command based on ssh login in linux system. When ssh public keys and aliases are configured, they are also common on scp

Thank you for reading this article carefully. I hope the article "what are the tips for using SSH commands" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report