這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)如何在centos 7中修改sshd,文章內(nèi)容豐富且以專(zhuān)業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)公司是一家專(zhuān)業(yè)提供霞山企業(yè)網(wǎng)站建設(shè),專(zhuān)注與成都網(wǎng)站建設(shè)、成都做網(wǎng)站、成都h5網(wǎng)站建設(shè)、小程序制作等業(yè)務(wù)。10年已為霞山眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)的建站公司優(yōu)惠進(jìn)行中。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
上述就是小編為大家分享的如何在centos 7中修改sshd了,如果剛好有類(lèi)似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)頁(yè)名稱(chēng):如何在centos7中修改sshd-創(chuàng)新互聯(lián)
本文地址:http://www.rwnh.cn/article10/ccidgo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營(yíng)銷(xiāo)推廣、靜態(tài)網(wǎng)站、網(wǎng)站導(dǎo)航、虛擬主機(jī)、網(wǎng)站內(nèi)鏈、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容