Linux remote login (putty and Xshell) and key settings

Remote login to linux system

1. Terminal putty and xshell

  1. Putty is a free and open source SSH client software, download address: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html  To download any software, you must go to the official website to download.
  2. xshell is a powerful secure terminal emulation software that supports SSH1, SSH2, and TELNET protocols for Microsoft Windows platforms

2. Install putty

  1. Click putty official website to enter the download page, select putty.zip to download.

  2. Unzip putty.zip, open PUTTY.EXE, fill in the server IP address in the HostName (or ip address) column, fill in a name in the Saved Sessions column, then click the Save button to save, and then click the Open button below to open the remote server Then, a window pops up, click "Yes" directly to enter the login page.

    Enter image description
    Enter image description
    Enter image description

3. Install xshell

  1. Click the Xshell official website to download directly. After the installation is complete, open xshell.
    Enter image description

  2. Click New in the upper left corner, fill in the name in the name column on the right, such as linux-ip-128, the protocol is SSH by default, the host (H) fills in the server IP address 192.168.88.128, and the port defaults to 22.
    Enter image description

  3. Click "User Authentication" on the left, the default method is "password", and fill in the user name and password.
    Enter image description
    Note: You can also change some other functions on the left here, such as the font, size, etc. in "Appearance".

  4. Click the "Confirm" button, select the newly created connection, and click the "Connect" button below. We connected to the server and entered the system. What’s better than putty here is that we don’t need to enter the user and password again.
    Enter image description
    Enter image description

4. Putty key authentication

  1. Generate a key pair Find PuTTYgen in the "Start" menu, click Open, and then click the Generate button to start generating the key. Shake the mouse to speed up the key generation. The key comment is the key name, which can be customized. Key passphrase: Use to set a password for the key, Confirm passphrase: Enter the password again.
    Enter image description

  2. Save the private key Click the Save private key button to save the private key, select a path and define the name putty-128, click the save button, this is the private key.
    Enter image description

  3. Copy the public key to linux

    a) First Key following contents copy it, it is the public key.
    SSH-RSA AAAAB3NzaC1yc2EAAAABJQAAAQEAmZ8cs69Xcb5mDnrxtgmoxVIEb4zPYgEgqg4117Q3QZzjV8I219 / WgvyYVgJlWV9 / t6H0WKmuDbjSgrq9ZedVh7khrUokzNOlDM7KKS8x0f5GBBWUMT20hCk02hLuAHCdNL6O2yYVUCdz2RAgt3 XeQ3WecjeBJmvGVTWQIoXzrtRvNOQdxYjAucruir0IcpQLWvRC31jIKPIG + + ouUjRNChFTo0HoaWxzNwA1Zpg7 / YpFjQU / wcVCSsjJFS / x5eAv7aojt4FcZhyuT + Wt7DxUQm7Lz / 70dH / 5LaQUZc5IMYoyYq1HRI9HmpCrcyVZymOcvT68sDaW2egaIjDqKskr3Q == Linux-IP-128

    b) 使用putty登陆服务器,然后按下面操作步骤来。    
    # mkdir /root/.ssh     //创建/root/.ssh目录,因为这个目录默认是不存在的    
    # chmod 700 /root/.ssh   //更改这个目录的权限    	    
    # vi /root/.ssh/authorized_keys   //把公钥内容复制进来    	
    
    [root@localhost ~]# mkdir /root/.ssh
    [root@localhost ~]# chmod 700 /root/.ssh
    [root@localhost ~]# vi /root/.ssh/authorized_keys
    [root@localhost ~]# vi /root/.ssh/authorized_keys
    [root@localhost ~]#
    

    Enter image description

Note: Press Enter directly after the vi command, enter i to enter the edit mode, then right-click to paste, press ESC, then enter ":wq" and press Enter, save and exit the file.
c) Close selinux Selinux is centos If you do not close selinux, when you use the key to log in, you will be prompted that the server refused our key, which will cause the login to fail. The running command is as follows:

# setenforce 0

This is only a temporary shutdown. After the next restart of linux, selinux will still start, so we have to permanently shut it down. The command is as follows:

# vi /etc/selinux/config

After pressing Enter, move the cursor, select the line SELINUX=enforcing, modify it to SELINUX=disabled, then press the ESC key, and then enter ":wq" to save and exit.

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
  1. Set putty to open the putty software through key login
    , find the session just now on the right, click to select, then click the load button on the right, then click the + in front of SHH on the left, then select auth, and view the private key file on the right for authentication : the bar below, currently empty. Click the Browse button, find the private key you just saved, and click the "Open" button. At this point, the long box has the address of the private key.
    Enter image description
    Enter image description

  2. Click the Open button at the bottom of the single machine, and the login interface will appear. At this time, the private key login interface will be displayed. The password must be entered as the password of the private key.
    Enter image description

5. Xshell key authentication

  1. Open xshell, click the "Tools" button above, and select "New User Key Generation Wizard (W)" Enter image description
  2. The default key type is RSA, and the key length can be selected. The longer it is, the more secure it is, and then click Next.
    Enter image description
  3. This interface waits for 2 seconds, the public key will be generated successfully, click Next.
    Enter image description
  4. The key name can be modified, then set a password, confirm the password, and click Next.
    Enter image description
  5. The public key that appears on the interface here is copied to the pasteboard, or you can click "Save File" to save the public key to the computer in case you forget it, and then click the "Finish" button.
    Enter image description
    Enter image description
  6. Re-open xshell, click "File" in the upper left corner, select "Properties", click "User Authentication" on the left, then click the method on the right, and select "public key"; for the user key, select "the name of the key, such as xshell- 128" and enter the password, click OK.
    Enter image description
    In this way, we successfully log in to the system with the key.
    Enter image description

The key to this remote login depends on personal habits. I prefer to use xshell, which is simple and convenient to use!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325114403&siteId=291194637