centos 7 修改sshd | 禁止 root登錄及sshd端口腳本定義
1.新建用戶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是大寫的"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
上面還是不能滿足輸出結(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 用戶登錄變化
[wwweee000@localhost ~]$
user普通用戶不能編輯/etc/ssh/sshd_config
,需要切換root才能編輯,切換root命令 : su
7.root進(jìn)行運(yùn)行,編寫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)文章
Linux文件操作新手指南之關(guān)于install命令的用法
這篇文章主要介紹了Linux文件操作新手指南之關(guān)于install命令的用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02Linux兩臺(tái)服務(wù)器之間復(fù)制文件及免密碼登錄的方法
有時(shí)候搭建集群機(jī)器是,需要在多臺(tái)機(jī)器中間相互拷貝文件,一種方式是同事sftp拷貝到本機(jī),再分別拷貝到其他服務(wù)器上。這里介紹一種直接在兩臺(tái)服務(wù)器之間拷貝文件且去掉繁瑣的登陸操作的方法2017-04-04分別在Linux和Windows下設(shè)置JVM內(nèi)存的簡(jiǎn)單方法
下面小編就為大家?guī)?lái)一篇分別在Linux和Windows下設(shè)置JVM內(nèi)存的簡(jiǎn)單方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01centos系統(tǒng)搭建本地yum服務(wù)器的方法
YUM是Yellow dog Updater, Modified的縮寫,是由Duke University所發(fā)起的計(jì)劃,目的就是為了解決RPM的依賴關(guān)系的問(wèn)題,方便使用者進(jìn)行軟件的安裝、升級(jí)等等工作。這篇文章主要給大家介紹了在centos系統(tǒng)搭建本地yum服務(wù)器的方法,有需要的朋友們可以參考借鑒。2016-12-12CentOS7 安裝 zabbix 4.0 教程(圖文詳解)
這篇文章主要介紹了CentOS7 安裝 zabbix 4.0 教程,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10