Centos7 modify the ssh port !, Centos7 modify ssh port

Source: Internet
Author: User
Tags openssh server ssh port

Centos7 modify the ssh port !, Centos7 modify ssh port

The default ssh port is 22, which is always scanned for logon!

To change the default port to 2218:


Modify the ssh configuration file/etc/ssh/sshd_config, remove the comment before Port 22, and change 22 to 2218

[root@niche ~]# whereis sshssh: /usr/bin/ssh /etc/ssh /usr/share/man/man1/ssh.1.gz[root@niche ~]# cd /etc/ssh[root@niche ssh]# lltotal 272-rw------- 1 root root     242153 Jun  9  2014 moduli-rw-r--r-- 1 root root       2123 Dec 18 10:03 ssh_config-rw-r--r-- 1 root root       2123 Dec 18 09:55 ssh_config.bak-rw------- 1 root root       4443 Dec 18 10:02 sshd_config-rw-r----- 1 root ssh_keys    227 Dec 16 01:29 ssh_host_ecdsa_key-rw-r--r-- 1 root root        162 Dec 16 01:29 ssh_host_ecdsa_key.pub-rw-r----- 1 root ssh_keys   1679 Dec 16 01:29 ssh_host_rsa_key-rw-r--r-- 1 root root        382 Dec 16 01:29 ssh_host_rsa_key.pub[root@niche ssh]# nano sshd_config


Modify iptables firewall:/etc/sysconfig/iptables

#-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT


Change

#-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT-A INPUT -p tcp -m state --state NEW -m tcp --dport 2218 -j ACCEPT


Save and exit

Restart iptables

[root@niche sysconfig]# systemctl stop iptables[root@niche sysconfig]# systemctl start iptables[root@niche sysconfig]# systemctl status iptablesiptables.service - IPv4 firewall with iptables   Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled)   Active: active (exited) since Thu 2014-12-18 10:11:13 EST; 5s ago  Process: 24537 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)  Process: 24605 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS) Main PID: 24605 (code=exited, status=0/SUCCESS)Dec 18 10:11:13 niche systemd[1]: Starting IPv4 firewall with iptables...Dec 18 10:11:13 niche iptables.init[24605]: iptables: Applying firewall rule...]Dec 18 10:11:13 niche systemd[1]: Started IPv4 firewall with iptables.Hint: Some lines were ellipsized, use -l to show in full.



Restart sshd

[root@niche sysconfig]# systemctl status sshdsshd.service - OpenSSH server daemon   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)   Active: active (running) since Thu 2014-12-18 10:05:25 EST; 6min ago  Process: 24469 ExecStartPre=/usr/sbin/sshd-keygen (code=exited, status=0/SUCCESS) Main PID: 24470 (sshd)   CGroup: /system.slice/sshd.service           └─24470 /usr/sbin/sshd -DDec 18 10:05:25 niche systemd[1]: Starting OpenSSH server daemon...Dec 18 10:05:25 niche systemd[1]: Started OpenSSH server daemon.Dec 18 10:05:25 niche sshd[24470]: Server listening on 0.0.0.0 port 2271.Dec 18 10:05:25 niche sshd[24470]: Server listening on :: port 2271.Dec 18 10:06:20 niche sshd[24476]: Accepted password for root from 113.99.1...h2Dec 18 10:07:03 niche sshd[24503]: Accepted password for root from 113.99.1...h2Hint: Some lines were ellipsized, use -l to show in full.


By default.fu@foxmail.com, welcome!


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.