Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux Remote Login

Linux Remote Login

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

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

In Linux systems, remote login is implemented through the ssh service; the default ssh service port is 22.

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

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

If you have downloaded Putty, double-click putty.exe and the following window pops up.

In the box below Host Name( or IP address), enter the IP of the remote server you want to log in to (you can view the server IP with the ifconfig command), then press Enter.

At this point, you are prompted to enter the username for logging in.

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


Remote login to Linux using key-based authentication

SSH is short for Secure Shell, defined by the IETF Network Working Group.

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

First use the tool PUTTYGEN.EXE to generate a key pair. After opening PUTTYGEN.EXE it looks like the following:

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

Then click Generate to start generating the key pair:

Note that during this process you must move the mouse back and forth, otherwise the progress bar will not move.

At this point the key pair has been generated. You can enter a passphrase for your key (in the Key Passphrase field) 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 storing them in a safe place, both to prevent others from peeking and to prevent accidental deletion. Next it's time to configure 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 directories; it will be described in detail later, so for now just understand it.

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

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

[root@localhost ~]# vim /root/.ssh/authorized_keys The vim command is used to edit a text file; it will also be described in detail in later chapters.

3) Open the public key file you just generated. It is recommended to open it with WordPad so it's easier to read. Copy all the content from the line starting with AAAA to the line "---- END SSH2 PUBLIC KEY ----" and paste it into the /root/.ssh/authorized_keys file, making sure all characters are on a single line. (You can first copy the content to Notepad, edit it into one line, and then paste it into the file.)

Here's a brief introduction on how to paste. After opening the file with vim, the file doesn't exist, so vim will create it automatically. Press the letter "i" and then press shift + Insert to paste (or just right-click with the mouse), provided the content has already been copied to the clipboard. After pasting, move the cursor to the very beginning of the line and type ssh-rsa , then press space. Then press ESC and type colon wq, i.e. :wq, to save. The format is shown below:

4) Then set the putty options: click SSh -> Auth on the left side of the window, click Browse... on the right side to select the private key you just generated, then click Open. At this point type root and you can log in without entering a password.

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