i. 在配置文件/etc/ssh/sshd_config
文件中修改linux
17 Port 5522
18 #AddressFamily any 19 #ListenAddress 0.0.0.0
20 #ListenAddress ::
ii. 而後重啓sshdvim
[root@localhost ~]# systemctl restart sshd
iii. 若是自定義端口,重啓sshd出現以下報錯:安全
[root@localhost ~]# systemctl restart sshd Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
查看詳細以下:dom
[root@localhost ~]# journalctl -xe -- -- Unit sshd.service has failed. -- -- The result is failed. Jul 19 22:39:08 localhost.localdomain systemd[1]: Unit sshd.service entered failed state. Jul 19 22:39:08 localhost.localdomain systemd[1]: sshd.service failed. Jul 19 22:39:08 localhost.localdomain polkitd[695]: Unregistered Authentication Agent for unix-process:3128:1153611 Jul 19 22:39:38 localhost.localdomain polkitd[695]: Registered Authentication Agent for unix-process:3140:1156691 (s Jul 19 22:39:38 localhost.localdomain systemd[1]: Starting OpenSSH server daemon... -- Subject: Unit sshd.service has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit sshd.service has begun starting up. Jul 19 22:39:38 localhost.localdomain sshd[3146]: error: Bind to port 5522 on 0.0.0.0 failed: Permission denied. Jul 19 22:39:38 localhost.localdomain sshd[3146]: error: Bind to port 5522 on :: failed: Permission denied. Jul 19 22:39:38 localhost.localdomain sshd[3146]: fatal: Cannot bind any address. Jul 19 22:39:38 localhost.localdomain systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a Jul 19 22:39:38 localhost.localdomain systemd[1]: Failed to start OpenSSH server daemon. -- Subject: Unit sshd.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit sshd.service has failed. -- -- The result is failed. Jul 19 22:39:38 localhost.localdomain systemd[1]: Unit sshd.service entered failed state. Jul 19 22:39:38 localhost.localdomain systemd[1]: sshd.service failed. Jul 19 22:39:38 localhost.localdomain polkitd[695]: Unregistered Authentication Agent for unix-process:3140:1156691
iv. 解決辦法,關閉SELinux便可ssh
# 臨時關閉 [root@localhost ~]# setenforce 0 # 永久關閉 [root@localhost ~]# vim /etc/selinux/config --------------------修改配置------------------------ SELINUX=disabled
v. 檢查是否成功tcp
注:若是重啓sshd成功沒有出現報錯,可是檢查端口時無效,也是跟SELinux有關,請把它Disable。ide
[root@localhost ~]# netstat -ntlp | grep sshd tcp 0 0 0.0.0.0:5522 0.0.0.0:* LISTEN 3166/sshd tcp6 0 0 :::5522 :::* LISTEN 3166/sshd
注:必須把上面的port 5522註釋掉,而後增長listenAddressspa
[root@localhost ~]# vim /etc/ssh/sshd_config ---------------- 配置以下 ---------------- #Port 5522 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: ListenAddress 0.0.0.0:22 ListenAddress 0.0.0.0:5522
重啓sshd:unix
[root@localhost ~]# systemctl restart sshd
檢查是否成功:rest
注:若是配置無效,請檢查SELinux是否Disable
[root@localhost ~]# netstat -ntlp | grep sshd tcp 0 0 0.0.0.0:5522 0.0.0.0:* LISTEN 3323/sshd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3323/sshd
收工!