日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ssh白名单_SSH密码登陆IP白名单

發布時間:2023/12/3 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ssh白名单_SSH密码登陆IP白名单 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在很多場景下,我們需要設置SSH密碼登陸IP白名單,只允許特定的IP地址使用密碼登陸。

首先,修改/etc/ssh/sshd_config配置文件,通過修改PasswordAuthentication全局關閉密碼登錄:

PasswordAuthentication no

1

PasswordAuthenticationno

然后,在/etc/ssh/sshd_config配置文件的末尾添加Match:

sshd_config中的Match

Match的語法是:

Match condition

Override config option 1

Override config option 2

1

2

3

Matchcondition

Overrideconfigoption1

Overrideconfigoption2

其中的條件包括:

User – Specifies the user to match. For example, if user is root allow login with ssh-keys but disallow everyone else.

Group – Specifies the group to match. For example, If user in group admin, allow login but disallow everyone else.

Host – Specifies the host to match

Address – Specifies the IP address or IP/subnet to match in CIDR format.

因此我們可以在sshd_config的最后增加:

Match Address XXX.XXX.XXX.XXX

PasswordAuthentication yes

1

2

MatchAddressXXX.XXX.XXX.XXX

PasswordAuthenticationyes

其中的XXX.XXX.XXX.XXX就是允許使用密碼登陸的IP地址,即所謂的白名單。其含義為,當登錄IP匹配XXX.XXX.XXX.XXX的形式時,允許采用密碼登錄。這里可以添加多個使用逗號分割的IP地址,也可以使用通配符、CIDR。

對于通配符而言:

* – It matches matches zero or more characters.

? – It matches exactly one character.

! – Patterns within pattern-lists may be negated with !.

例如:

## Match 192.168.1.1 to 192.168.1.9 ##

Match Address 192.168.1.?

PermitRootLogin yes

## Match 192.168.1.{2,3....} ##

Match Address 192.168.2.*

X11Forwarding no

## Allow any host in the ".home.lan" set of domains ##

Match Host *.home.lan

X11Forwarding yes

## Allow everyone except foo user ##

Match User *,!foo

X11Forwarding yes

PermitTunnel yes

PermitTTY no

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

## Match 192.168.1.1 to 192.168.1.9 ##

MatchAddress192.168.1.?

PermitRootLoginyes

## Match 192.168.1.{2,3....}??##

MatchAddress192.168.2.*

X11Forwardingno

## Allow any host in the ".home.lan" set of domains ##

MatchHost *.home.lan

X11Forwardingyes

## Allow everyone except foo user ##

MatchUser *,!foo

X11Forwardingyes

PermitTunnelyes

PermitTTYno

最后,重啟sshd服務:

systemctl restart sshd

1

systemctlrestartsshd

我們就會發現之前能夠使用密碼登陸的機器已經不能登陸了:

SSH被限制為僅有指定IP能夠使用密碼登陸

參考資料:

1、https://www.cyberciti.biz/faq/match-address-sshd_config-allow-root-loginfrom-one_ip_address-on-linux-unix/

總結

以上是生活随笔為你收集整理的ssh白名单_SSH密码登陆IP白名单的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。