溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

centos7版本中ssh的相關(guān)設(shè)置

發(fā)布時(shí)間:2021-09-15 18:07:56 來源:億速云 閱讀:162 作者:chen 欄目:建站服務(wù)器

本篇內(nèi)容介紹了“centos7版本中ssh的相關(guān)設(shè)置”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

1.設(shè)置SSH連接端口
1.1.關(guān)閉SELinux
--關(guān)閉系統(tǒng)當(dāng)前selinux
# setenforce 0  
--關(guān)閉系統(tǒng)永久selinux
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

1.2.編輯/etc/ssh/sshd_config,修改端口(22->26),并重啟sshd
# vi /etc/ssh/sshd_config
Port 26
# grep ^Port /etc/ssh/sshd_config

# systemctl restart sshd

1.3.修改firewalld規(guī)則,允許tcp/26端口
# firewall-cmd --permanent --zone=public --add-port=26/tcp
# firewall-cmd --reload

#確認(rèn)修改
# firewall-cmd --list-all |grep 26

這樣,可以就通過26端口連接ssh。
上述過程中,如修改ssh端口后,重啟sshd時(shí)報(bào)錯(cuò),而注釋掉修改又能正常重啟,用getenforce檢查selinux是否已關(guān)閉。

2、禁止root遠(yuǎn)程ssh(默認(rèn)為禁止)
2.1.編輯sshd_config
# vi /etc/ssh/sshd_config
PermitRootLogin no
--確認(rèn)修改
# grep ^PermitRootLogin /etc/ssh/sshd_config

2.2.重啟sshd
# systemctl restart sshd

3.限制ssh遠(yuǎn)程訪問的IP
--編輯/etc/hosts.allow,添加如下內(nèi)容
# echo "sshd:192.168.1.111:allow" >>/etc/hosts.allow
--編輯hosts.deny,添加如下內(nèi)容
# echo "sshd:ALL" >>/etc/hosts.deny
此外,還可通過修改sshd_config限制通過ssh遠(yuǎn)程訪問的IP,還可使用firewalld對(duì)IP進(jìn)行限制。

4.限制ssh訪問的用戶名
--修改sshd_config,允許ssh遠(yuǎn)程訪問服務(wù)器的test用戶(多個(gè)用戶空格分隔,默認(rèn)拒絕其他所有用戶)
# echo "AllowUsers test" >>/etc/ssh/sshd_config

--重啟sshd
# systemctl restart sshd

5.獲取ssh的相關(guān)信息
5.1.獲取sshd位置
# whereis sshd
5.2.獲取ssh版本
# ssh -V

#5.3.查看sshd程序相關(guān)信息
# strings /usr/sbin/sshd |grep OpenSSH6.6

#5.4.sed更改版本信息
--先備份原有信息
# cp -p /usr/sbin/sshd ./sshd_bk
--更改版本信息
# sed -i 's/OpenSSH_6.6/OpenSSH_7.4/g' /usr/sbin/sshd

#5.5.重啟sshd
[root@imzcy ~]# systemctl restart ssh

“centos7版本中ssh的相關(guān)設(shè)置”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI