Linux remote login


Linux is generally used as a server, and the server is usually placed in the computer room. You cannot operate your Linux server in the computer room.

At this time we need to log in to the Linux server remotely to manage and maintain the system.

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

Linux remote login clients on Windows systems include SecureCRT, Putty, SSH Secure Shell, etc. This article uses Putty as an example to log in to the remote server.

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

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

5_1.png

Enter the remote server IP you want to log in to in the box below Host Name (or IP address) (you can check the server IP through the ifconfig command), and then press Enter.

5_12.png

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

5_13.png

Enter root and press Enter, then enter the password to log in to the remote Linux system.

5_14.png


Use key authentication mechanism to log in to linux remotely

SSH is the abbreviation of Secure Shell, which is developed by the IETF Network Working Group formulated.

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

First use the tool PUTTYGEN.EXE to generate a key pair. After opening the tool PUTTYGEN.EXE, as shown in the figure below:

5_15.png

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

5_16.png

and then click Generate to start generating the key pair:

5_17.png

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

5_18.png

At this point, the key pair has been generated. You can enter a password for your key (in Key Passphrase) or leave it blank. Then click Save public key to save the public key, and click Save private Key to save the private key. The author recommends that you put it in a relatively safe place, firstly to prevent others from prying, and secondly to prevent accidental deletion. Next it’s time to set up on the remote Linux host.

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

[root@localhost ~]# mkdir /root/.ssh The mkdir command is used to create the directory. It will be introduced in detail later. For now Just understand.

[root@localhost ~]# chmod 700 /root/.ssh The chmod command is used to modify file attribute permissions, which will be introduced in detail later.

2) Create file / root/.ssh/authorized_keys

[root@localhost ~]# vim /root/.ssh/authorized_keys The vim command is a command to edit a text file, also in Detailed introduction is provided in subsequent chapters.

3) Open the public key file just generated. It is recommended to use WordPad to open it so that it looks more comfortable. Copy the line from the beginning of AAAA to "---- END SSH2 PUBLIC KEY ----" Paste all the contents into the /root/.ssh/authorized_keys file, making sure that all characters are on one line. (You can first copy the copied content to Notepad, then edit it into one line and paste it into the file).

Here I would like to briefly introduce how to paste. After opening the file with vim, the file does not exist, so vim will automatically create it. Press the letter "i" and then press shift + Insert at the same time to paste (or just click the mouse on the email), assuming it has been copied to the clipboard. After pasting, move the cursor to the front of the line and enter ssh-ras, then press space. Press ESC again, then enter the colon wq or :wq to save. The format is as follows:

5_19.png

4) Then set the putty options, click SSh on the left side of the window -> Auth, click Browse on the right side of the window... Select the private key you just generated key, then click Open, enter root at this time, and you can log in without entering a password.

5_20.png

If you set Key Passphrase earlier, you will be prompted to enter the password at this time. For greater security, it is recommended that you set up a Key Passphrase.