Akemi

SSH跳板

2025/02/13

现在有ABC三台主机,当前用的是A主机,B和C主机属于不同网络环境
这个时候需要登录C主机,就需要先登录B然后登录C,
如果需要传文件,那就需要传两次,更加麻烦

那么有没有更方便的方法呢?

有的,就是ssh跳板

主要是linux主机比较需要,Windows有各种各样的图形化软件,鼠标点点点就能配

这里以ubuntu为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cat ~/.ssh/config
Host B
HostName B
User root
IdentityFile
Host C
HostName C
User lviz
ProxyJump B 指定以B为跳板连接到C
IdentityFile

Host--别名
HostName--host地址,也就是ip地址
User--登录的用户
IdentityFile--可选项,指定对方的私钥,做免密登录

注:
1.配置仅对当前用户有效,如果使用sudo提权就无法使用该config,如果要在root使用,则需要在/root/.ssh中添加
2.Host别名优先级高于/etc/hosts,即使/etc/hosts没有定义也可以使用

验证

1
2
3
4
5
6
7
ssh lviz@xxxxxxxx
root@xxxxxxx's password:
lviz@xxxxxxx's password:
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-1058-aws x86_64)

复制
sudo scp lviz@xxxx:/home/xxxx.yaml .
CATALOG