Optimize centos remote SSH connection

Source: Internet
Author: User

Optimize centos remote SSH connection

1.

① Run the ls-l/etc/init. d/sshd command to view the sshd service.

② Run the ps-ef | grep sshd command to view the sshd process.

2. The difference between ssh_config and sshd_config indicates that the local client represents the server:

3. Run the ll/etc/ssh/sshd_config command to view the sshd configuration file:

4. Before modifying the configuration file, back up the file in the format of host name time and date. Here, back up/etc/ssh/sshd_config to/etc/ssh/sshd_config.you.20160222.

5. Run the set nu command in vi command mode to set the row number:

6. modify the configuration file as follows:

A. Change "yes" of useDNS to "no:

B. Convert the original listening address 0.0.0.0 to the Intranet IP address 192.168.65.130:

After modifying the listening address, the sshd service only accepts or only uses 192.168.65.130 as the valid ip Address:

C. Change "yes" to "no" for disabling root remote connection:

D. Search for GSSAuthentication and change the default yes value to no:

F. Modify the port number to change the original remote connection port 22 to 52113:

7. Modify the sshd configuration in batches:

A. Directly paste the configuration to be modified into/etc/ssh/sshd_config (it seems that the level of no is more advanced ?)

B. Use the sed command for batch modification: sed-ir '13 iport 52113 \ nPermitRootLogin no \ nPermitEmptyPasswds no \ nUseDNS no \ nGSSAPIAuthentication no 'sshd_config

8. Compare the differences between the original file and the modified file:

1. Use the diff command:

2. Use the vimdiff command (more powerful and highlighted ):

9. restart the sshd service through the/etc/init. d/sshd restart and/etc/init. d/sshd reload commands to make the configuration take effect:

10. Dos may occur after the configuration file has been modified:

Apparently, because the previous port number was changed from 22 to 52113, but the session options of the fast connection of SecureCRT were not changed, it does not match the natural connection:

After the modification, you can log on again and find that you can connect again:

If the port is modified, the connection that logs in with the port before modification is still active and the connection fails once it is logged out:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.