8

ssh 可以设置常用地登录吗?

 3 years ago
source link: https://www.v2ex.com/t/778496
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Python

ssh 可以设置常用地登录吗?

  chenqh · 1 天前 · 1399 次点击

如题,想 qq 常用地那样?

19 条回复    2021-05-23 14:17:50 +08:00

cherbim   1 天前 via Android

只允许指定 ip 登录,在 sshd_config 配置文件里,allowusers

wzhpro   1 天前

没必要,证书认证+动态验证码 已经够强了

chenqh   1 天前

知道怎么做了,但是不会搞 pam,还是算了把,不做了

yanqiyu   1 天前

其实没必要用 pam,直接防火墙拦截掉除了常用 ip 之外的 port22 入站就行

ronman   1 天前

证书+禁 root+fail2ban

uncat   1 天前

本地维护一份 ~/.ssh/config 配置. 将 git 仓库中的 config 文件软链到 ~/.ssh/config. 然后 config 就可以版本控制了.
然后. 用如下的配置模板为每个项目的服务器添加一份配置.

Host project-1
User <username1>
HostName <IP1>
ProxyJump <username2>@<IP2>

project-1 是一个 nickname.
<username1> 是登陆服务器的地址.
<IP1> 是服务器的 IP.
<username2> 是 ssh 登陆跳转服务器的地址.
<IP2> 是跳转服务器的 IP.
添加了这样的配置后. 登陆服务器. 以往的命令: ssh <username1>@<IP1> 就会变成 ssh project-1. 这里面 <username2>@<IP2> 对应的跳转服务器的作用是: 在你每次 ssh project-1 时, 流量都会先发给 <username2>@<IP2> 对应的跳转服务器, 由跳转服务器发出. 这样, 你所有的 ssh 登陆请求就会有一个固定的来源 IP 了. 这个 IP 就是 IP2(跳转服务器的 IP). 一般云服务商都一提供网络安全组. 将 22 端口设为只允许 IP 登陆即可.

最终你的 git 仓库中的 config 文件会变成下面的形式:

Host project-1
User <username1>
HostName <IP1>
ProxyJump <username2>@<IP2>

Host project-3
User <username3>
HostName <IP3>
ProxyJump <username2>@<IP2>

Host project-4
User <username4>
HostName <IP4>
ProxyJump <username2>@<IP2>

Host project-5
User <username5>
HostName <IP5>
ProxyJump <username2>@<IP2>

# 类似上面的形式. 每次有新的项目. 就添加一个块. 然后推送到远程仓库. 让其他小伙伴拉取这个仓库. 添加软链接到 ~/.ssh/config 即可.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK