Modify SSH default port in CentOS

Source: Internet
Author: User


Modify the SSH default Port in CentOS. First, modify the configuration file vi/etc/ssh/sshd_config to find # Port 22. Here, the Port 22 is used by default and changed to the following: port 22 www.2cto.com Port 800 and save and run/etc/init. SSH ports such as d/sshd restart will work on both 22 and 800. Now, edit the firewall configuration: vi/etc/sysconfig/iptables to enable port 800. Run/etc/init. d/iptables restart. now use the ssh tool to connect to port 800 to test whether the restart is successful. If the connection is successful, edit the settings of sshd_config again and delete Port22. The reason for setting two ports first and then disabling one after the test is successful is to prevent unknown situations such as disconnection, network disconnection, and misoperation during the conf modification process, you can also connect to the debugging through another port to prevent connection failures and contact the data center for debugging, which makes the problem more complicated and troublesome. To enhance security, first add a user with normal permissions: # useradd uploader # passwd uploader // set the password www.2cto.com production machine to prohibit ROOT remote SSH login: # vi/etc/ssh/sshd_config change PermitRootLogin yes to PermitRootLogin no restart sshd service # service sshd restart www.2cto.com remote management use normal user uploader to log on, then use su root to switch to the root user and get the highest permission to modify the normal user with the root permission. 1) enter the Super User mode. That is, enter "su-". The system will ask you to enter the superuser password and enter the password to enter the superuser mode. (You can also use root directly) 2) Add the write permission for the file. That is, enter the command "chmod u + w/etc/sudoers ". 3) edit the/etc/sudoers file. That is, enter the command "vim/etc/sudoers", enter "I" to enter the editing mode, and find this line: "root ALL = (ALL) ALL "add" xxx ALL = (ALL) ALL "(here xxx is your user name), save it (that is, Press Esc first, and then enter ": wq ") quit. 4) revoke the write permission of a file. That is, enter the command "chmod u-w/etc/sudoers ". Author: paulfzm

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.