SSH port modification and limit IP logon and prevent root Telnet method

Source: Internet
Author: User
Tags iptables ssh port firewall

1. Modify SSH default port

The code is as follows Copy Code

Modify configuration file
Vi/etc/ssh/sshd_config
The modified #Port 22 is as follows:
Port 22
Port 888
Reboot SSH Service
/etc/init.d/sshd restart

This will also be valid for SSH Ports 22 and 888.

The code is as follows Copy Code

Modify firewall configuration
Vi/etc/sysconfig/iptables
Enable Port 888
-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 888-j ACCEPT
Reboot firewall
/etc/init.d/iptables restart

You can now use the SSH tool to connect to port 888 to test for success. If the connection succeeds, edit the Sshd_config settings and the port of the firewall again, remove the Port22 from the inside, and then restart the access rules for the SSH service and firewall.

2. Prevent root remote Login

The code is as follows Copy Code

Add a user with normal permissions first
Useradd phpha_com
passwd phpha_com
Prevent root remote SSH logon
Vi/etc/ssh/sshd_config
Modify
Permitrootlogin Yes
To
Permitrootlogin No
Restart the sshd service
Service sshd Restart

Remote admin login with normal user phpha_com and then use SU root to switch to root to get maximum privileges

3. Restrict SSH login IP address

<1> add IP to allow access

The code is as follows Copy Code

Vi/etc/hosts.allow
sshd:115.183.13.130

<2> prohibit all other IP

  code is as follows copy code

     vi/etc/hosts.deny
    sshd:all

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.