centos 7 修改sshd | 禁止 root登錄及sshd端口腳本定義
1.新建用戶(hù)wwweee000
[root@localhost ~]# useradd wwweee000 [root@localhost ~]# passwd wwweee000 Changing password for user wwweee000. New password: BAD PASSWORD: The password is a palindrome Retype new password: passwd: all authentication tokens updated successfully.
2.#Port 22字段刪掉,將22改為其他不被使用的端口,服務(wù)器端口最大可以開(kāi)到65536.//注意Port是大寫(xiě)的"P"
[root@localhost ~]# cat -n /etc/ssh/sshd_config|grep "Port *" 17 #Port 22 100 #GatewayPorts no [root@localhost ~]# cat /etc/ssh/sshd_config|grep -n "Port *" 17:#Port 22 100:#GatewayPorts no [root@localhost ~]# awk "/Port */" /etc/ssh/sshd_config #Port 22 #GatewayPorts no
上面還是不能滿(mǎn)足輸出結(jié)果:我們只要Port 22的答案.
[root@localhost ~]# cat /etc/ssh/sshd_config|grep -n "Port\ " 17:#Port 22 [root@localhost ~]# cat -n /etc/ssh/sshd_config|grep "Port\ " 17 #Port 22 [root@localhost ~]# cat /etc/ssh/sshd_config|grep -n "Port\ " 17:#Port 22 [root@localhost ~]# awk "/Port\ /" /etc/ssh/sshd_config #Port 22 [root@localhost ~]# sed -i "17s/#Port 22/Port 22/g" /etc/ssh/sshd_config [root@localhost ~]# awk "/Port\ /" /etc/ssh/sshd_config Port 22
-n顯示行號(hào);\反斜杠實(shí)質(zhì)定義
3.不使用vi/vim進(jìn)行修改Port 22 為 4096
[root@localhost ~]# sed -i "17s/Port 22/Port 4096/g" /etc/ssh/sshd_config [root@localhost ~]# cat /etc/ssh/sshd_config|grep "Port\ " Port 4096
4.修改 #PermitRootLogin yes 為 PermitRootLogin no
[root@localhost ~]# cat -n /etc/ssh/sshd_config|grep "PermitRootLogin" 49 #PermitRootLogin yes 104 # the setting of "PermitRootLogin without-password". [root@localhost ~]# sed -i "49s/#PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config [root@localhost ~]# cat -n /etc/ssh/sshd_config|grep "PermitRootLogin no" 49 PermitRootLogin no
5.重啟sshd服務(wù)
[root@localhost ~]# systemctl restart sshd.service
6.使用 wwweee000 用戶(hù)登錄變化
[wwweee000@localhost ~]$
user普通用戶(hù)不能編輯/etc/ssh/sshd_config,需要切換root才能編輯,切換root命令 : su
7.root進(jìn)行運(yùn)行,編寫(xiě)shell腳本。//腳本通用centos 7 (主要:sshd_config端口號(hào)定義輸入對(duì)root登錄禁止)
#!/bin/bash sshd_Port=`cat /etc/ssh/sshd_config|grep "Port\ "` echo " 當(dāng)前sshd端口:$sshd_Port" read -ep " 請(qǐng)輸入sshd服務(wù)的連接端口Port (1-65536); 請(qǐng)確保其他端口沖突和防火墻端口開(kāi)放業(yè)務(wù):" sshd_Port_read echo " 你輸入的端口號(hào):$sshd_Port_read" sed -i "s/$sshd_Port/Port $sshd_Port_read/g" /etc/ssh/sshd_config echo " 已經(jīng)設(shè)置端口為:`cat /etc/ssh/sshd_config|grep "Port\ "`" sed -i "s/#PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config systemctl restart sshd.service exit 0
運(yùn)行測(cè)試(可循環(huán)使用)本次防火墻關(guān)閉/生產(chǎn)服務(wù)器都是關(guān)閉防火墻的
[root@localhost wwweee000]# firewall-cmd --state not running [root@localhost ~]# sh sshd_config_Port.sh 當(dāng)前sshd端口:Port 22 請(qǐng)輸入sshd服務(wù)的連接端口Port (1-65536) 請(qǐng)確保其他端口沖突和防火墻端口開(kāi)放業(yè)務(wù):4096 你輸入的端口號(hào):4096 已經(jīng)設(shè)置端口為:Port 4096
總結(jié)
以上所述是小編給大家介紹的centos 7 修改sshd | 禁止 root登錄及sshd端口腳本定義,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
CentOS7如何執(zhí)行PHP定時(shí)任務(wù)詳解
這篇文章主要給大家介紹了關(guān)于在CentOS7中如何執(zhí)行PHP定時(shí)任務(wù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11
linux環(huán)境搭建圖數(shù)據(jù)庫(kù)neo4j的講解
今天小編就為大家分享一篇關(guān)于linux環(huán)境搭建圖數(shù)據(jù)庫(kù)neo4j的講解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-04-04
Linux實(shí)現(xiàn)自動(dòng)登錄的實(shí)例講解
在本篇文章里小編給大家分享的是關(guān)于Linux實(shí)現(xiàn)自動(dòng)登錄的相關(guān)實(shí)例以及知識(shí)點(diǎn),需要的朋友們參考學(xué)習(xí)下。2019-10-10
linux上安裝zookeeper 啟動(dòng)和關(guān)閉的教程
這篇文章主要介紹了linux上安裝zookeeper 啟動(dòng)和關(guān)閉的教程詳解,首先zookeeper運(yùn)行需要java環(huán)境所以必須先裝JDK,具體操作步驟大家一起看看本文吧2018-08-08
詳解如何在 Linux 啟動(dòng)時(shí)自動(dòng)執(zhí)行命令或腳本
這篇文章主要介紹了詳解如何在 Linux 啟動(dòng)時(shí)自動(dòng)執(zhí)行命令或腳本,主要有兩種方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03
apache配置php實(shí)現(xiàn)單一入口方法
這篇文章主要介紹了apache配置php實(shí)現(xiàn)單一入口方法,大家參考使用2013-12-12
CentOS系統(tǒng)下Apache配置多域名或多端口映射的方法
我們大多情況是一臺(tái)服務(wù)器一個(gè)IP,這樣配置起來(lái)很簡(jiǎn)單,但是如何想多域名多端口映射的話(huà)就沒(méi)那么簡(jiǎn)單了,下面這篇文章主要介紹了CentOS系統(tǒng)下Apache配置多域名或多端口映射的方法,需要的朋友可以參考學(xué)習(xí),下面來(lái)一起看看吧。2016-12-12

