Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Linux logs on remotely


May 22, 2021 Linux


Table of contents


Linux is generally used as a server, while servers are generally placed in the room, and you can't operate your Linux server in the room.

At this point, we need to log on remotely to the Linux server to manage the maintenance system.

The CentOS system installs openssh by default

If there is no installation, you can use the command to install:

yum install openssh-server -y

The remote login function in linux system is implemented through the ssh service, the default ssh service port number is 22.

Linux remote login clients on Windows systems are SecureCRT, Putty, SSH Secure Shell, Xshell, etc., and this article uses Putty as an example to log on to the remote server.

Putty download address: http://www.putty.org/

If you downloaded putty, double-click putty .exe pop up the following window.

Linux logs on remotely

Enter the remote server IP you want to log on to in the box below Host Name (you can view the server ip through the ifconfig command) and return.

Linux logs on remotely

At this point, we are prompted to enter the user name to sign in.

Linux logs on remotely

Enter root and enter the car, then enter the password, you can log on to the remote linux system.

Linux logs on remotely


Use the key authentication mechanism to log in to linux remotely

SSH is an acronym for Secure Shell and was developed by the Network Working Group of the IETF.

SSH is a security protocol based on the application layer and the transport layer.

Start with the tool PUTTYGEN. E XE generated the key pair. After opening the tool PUTTYGEN.EXE as shown in the following image:

Linux logs on remotely

The tool can generate keys in three formats: SSH-1 (RSA) SSH-2 (RSA) SSH-2 (DSA), which we use the default format, SSH-2 (RSA). N umber of bits in a generated key this refers to the size of the generated key, the higher the number, the more complex the generated key, the higher the security. Here we write 2048.

Linux logs on remotely

Then click Generate to start generating the key pair:

Linux logs on remotely

Note that in this process the mouse to move back and forth, otherwise this progress bar will not move.

Linux logs on remotely

By this point, the key pair has been generated. Y ou can enter a password for your key or leave it blank (at Key Passphrase). T hen point Save public key to save the public key, point Save private Key to save the private key. T he author suggests that you put in a safer place, one to prevent others from voyeurism, two to prevent false deletion. Next, it's time to set it up on the remote linux host.

1) Create a directory /root/.ssh and set permissions

The root@localhost command is used to create a directory, which will be described in more detail later, for the time being.

The root@localhost command is used to modify file property permissions and will be described in more detail later.

2) Create a file / root/.ssh/authorized_keys

The root@localhost the vim/root/.ssh/authorized_keys vim command is a command to edit a text file, also detailed in a later section.

3) Open the public key file just generated, it is recommended to use the writing board to open, so look comfortable, copy everything from the beginning of AAA to the ---- END SSH2 PUBLIC KEY ----" line, paste into the /root/.ssh/authorized_keys file, to ensure that all characters are on one line. (You can copy the copied content to Note book and then edit it into a line and paste it into the file.)

Here is a brief introduction, how to paste, with vim to open that file, the file does not exist, so vim will be created automatically. P ress the letter "i" and paste it at the same time by pressing shift and Insert (or right-click it), provided it has been copied to the cutboard. W hen pasted, move the cursor to the front of the line and enter ssh-rsa, then press the space. P ress ESC again, and then enter the colon wq i.e.: wq and save it. The format is as follows:

Linux logs on remotely

4) Set the putty option again, click On the left side of the window, click Browse on the right side of the window... Select the private key you just generated, and then point open, and enter root at this time, you can log in without entering a password.

Linux logs on remotely

If you set Key Passphrase earlier, you'll be prompted to enter your password. For added security, it is recommended that you set up a Key Passphrase.