Easy Tutorial
❮ Linux Comm Mformat Linux Comm Od ❯

Linux Remote Login

Linux is commonly used as a server, and servers are typically located in data centers, so you cannot operate your Linux server directly in the data center.

In this case, we need to remotely log in to the Linux server to manage and maintain the system.

The remote login functionality in Linux systems is implemented through the ssh service, with the default ssh service port number being 22.

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

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

If you have downloaded Putty, please double-click putty.exe and a window will pop up as follows.

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

At this point, it prompts us to enter the username to log in.

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


Remote Login to Linux Using Key Authentication Mechanism

SSH stands for Secure Shell, which is formulated by the Network Working Group of the IETF.

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 the tool PUTTYGEN.EXE, it looks like this:

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

Then click Generate to start generating the key pair:

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

At this point, the key pair has been generated. You can enter a password 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. It is recommended to place them in a secure location to prevent theft and accidental deletion. Next, you need 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 directories, which will be introduced in detail later.

[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 the file /root/.ssh/authorized_keys

[root@localhost ~]# vim /root/.ssh/authorized_keys The vim command is used to edit a text file, which will be introduced in detail later.

3) Open the previously generated public key file, it is recommended to use a notepad for better readability. Copy all content from the beginning with AAAA to the line "---- END SSH2 PUBLIC KEY ----", and paste it into the /root/.ssh/authorized_keys file, ensuring all characters are on one line. (You can first copy the content to Notepad and edit it into one line before pasting it into the file).

Here is a brief introduction on how to paste. After opening the file with vim, since the file does not exist, vim will automatically create it. Press the letter "i" and then press shift + Insert to paste (or simply right-click the mouse), provided that the content has been copied to the clipboard. After pasting, move the cursor to the front of the line and enter ssh-rsa, then press Space. Press ESC, then enter :wq to save. The format looks like this:

4) Set the putty options, click on SSH -> Auth in the left window, click Browse... in the right window to select the just-generated private key, then click Open. At this point, enter root, and you will not need to enter the password to log in.

If you set a Key Passphrase earlier, it will prompt you to enter the password at this point. For added security, it is recommended to set a Key Passphrase.

❮ Linux Comm Mformat Linux Comm Od ❯