婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > centos 7 修改sshd | 禁止 root登錄及sshd端口腳本定義

centos 7 修改sshd | 禁止 root登錄及sshd端口腳本定義

熱門標簽:靈圖uu電子寵物店地圖標注 山東企業外呼系統公司 地圖標注如何改成微信號 地圖標注黃河的位置 濮陽好的聯通400電話申請 百度地圖標注公司位置要多少錢 虛假地圖標注 400電話號碼辦理多少錢 承德地圖標注公司

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改為其他不被使用的端口,服務器端口最大可以開到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

上面還是不能滿足輸出結果:我們只要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顯示行號;\反斜杠實質定義

3.不使用vi/vim進行修改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服務

[root@localhost ~]# systemctl restart sshd.service

6.使用 wwweee000 用戶登錄變化

[wwweee000@localhost ~]$

user普通用戶不能編輯/etc/ssh/sshd_config,需要切換root才能編輯,切換root命令 :  su

7.root進行運行,編寫shell腳本。//腳本通用centos 7 (主要:sshd_config端口號定義輸入對root登錄禁止)

#!/bin/bash
sshd_Port=`cat /etc/ssh/sshd_config|grep "Port\ "`
echo "  當前sshd端口:$sshd_Port"
read -ep "  請輸入sshd服務的連接端口Port (1-65536);
  請確保其他端口沖突和防火墻端口開放業務:" sshd_Port_read
echo "  你輸入的端口號:$sshd_Port_read"
sed -i "s/$sshd_Port/Port $sshd_Port_read/g" /etc/ssh/sshd_config
echo "  已經設置端口為:`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

運行測試(可循環使用)本次防火墻關閉/生產服務器都是關閉防火墻的

[root@localhost wwweee000]# firewall-cmd --state 
not running
[root@localhost ~]# sh sshd_config_Port.sh 
  當前sshd端口:Port 22
  請輸入sshd服務的連接端口Port (1-65536)
  請確保其他端口沖突和防火墻端口開放業務:4096
  你輸入的端口號:4096
  已經設置端口為:Port 4096

總結

以上所述是小編給大家介紹的centos 7 修改sshd | 禁止 root登錄及sshd端口腳本定義,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!

標簽:德宏 鷹潭 上海 樂山 安康 福州 淮安 泰安

巨人網絡通訊聲明:本文標題《centos 7 修改sshd | 禁止 root登錄及sshd端口腳本定義》,本文關鍵詞  centos,修改,sshd,禁止,root,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《centos 7 修改sshd | 禁止 root登錄及sshd端口腳本定義》相關的同類信息!
  • 本頁收集關于centos 7 修改sshd | 禁止 root登錄及sshd端口腳本定義的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 高雄县| 巍山| 陈巴尔虎旗| 武川县| 昔阳县| 衡阳市| 井冈山市| 汉川市| 涟水县| 武宁县| 建德市| 武宣县| 宜良县| 越西县| 靖远县| 许昌市| 灵山县| 绥宁县| 莒南县| 台州市| 景宁| 含山县| 咸丰县| 永安市| 高台县| 长乐市| 邵阳县| 临洮县| 公安县| 灵寿县| 申扎县| 安庆市| 汕尾市| 深水埗区| 五家渠市| 黄浦区| 滁州市| 旬阳县| 泸定县| 东兴市| 梁山县|