我正在尝试设置具有远程端口转发的 ssh 隧道。这个想法是让 VPS 作为 ssh 进入远程部署系统(目前包含 Raspberry Pi)的一种手段。一切似乎都正常,但在尝试将所有参数移至 ~/.ssh/config 文件时遇到问题。起作用的是主机名、用户、端口和身份文件的设置。但是设置 RemoteForward 参数似乎不起作用。
以下作品:
ssh -R 5555:localhost:22 ssh-tunnel
Run Code Online (Sandbox Code Playgroud)
然而,当在配置文件中使用以下行时;
Host ssh-tunnel
...
RemoteForward 5555 localhost:22
Run Code Online (Sandbox Code Playgroud)
以下命令返回消息“错误的远程转发规范‘ssh-tunnel’”
ssh -R ssh-tunnel
Run Code Online (Sandbox Code Playgroud) 我正在编写一个 shell 脚本,我需要IdentityFile从 ssh 配置文件中获取 。ssh 配置文件如下所示:
\xe2\x80\x8bHost AAAA\n User aaaa\n IdentityFile /home/aaaa/.ssh/aaaaFILE\n IdentitiesOnly yes\n PubkeyAuthentication=yes\n PreferredAuthentications=publickey\n\xe2\x80\x8bHost BBBB\n User bbbb\n IdentityFile /home/aaaa/.ssh/bbbbFILE\n IdentitiesOnly yes\n PubkeyAuthentication=yes\n PreferredAuthentications=publickey\n\xe2\x80\x8bHost CCCC\n User cccc\n IdentityFile /home/aaaa/.ssh/ccccFILE\n IdentitiesOnly yes\n PubkeyAuthentication=yes\n PreferredAuthentications=publickey\nRun Code Online (Sandbox Code Playgroud)\n\nIdentityFile我想根据给定获取后面的字符串Hostname并将其放入变量中。主机名将由名为 的 shell 变量提供${HOSTNAME}。
我能够使用Bash extract user for a certain host from ssh config fileIdentityFile的答案来读取配置文件,并根据单个特定的 grep 获取单个特定的内容Hostname,但我无法掌握将变量传递到awk。
到目前为止我已经尝试过
\n\nSSH_CONFIG="/home/aaaa/.ssh/config"\n# Note AAAA is the hostname for this case\nKEY=$(awk \'/^Host …Run Code Online (Sandbox Code Playgroud) 我使用 bitbucket 来托管一些 git 存储库。
当我尝试做:
git pull && git push
Run Code Online (Sandbox Code Playgroud)
我得到:
mux_client_request_session: session request failed: Session open refused by peer
ControlSocket /home/ravi/.ssh/sockets/socket-git@bitbucket.org:22 already exists, disabling multiplexing
Run Code Online (Sandbox Code Playgroud) 我可以使用一些CLI工具来验证known_hosts的内容吗?也许尝试对其中的所有主机执行ping操作,看看是否可以连接到每个主机?
可能使用ssh-keygen或ssh-keyscan?
我有一个 SSH 配置文件,如:
Host myAlias
HostName the.actual.host.name.com
Run Code Online (Sandbox Code Playgroud)
是否可以从别名、shell 而不连接到主机来解析主机名?我的目标是:
$ <something> myAlias
the.actual.host.name.com
Run Code Online (Sandbox Code Playgroud) 我正在尝试连接到 GCP 实例,该实例每次重新启动时都会更改其公共 IP。要动态获取 IP,我使用以下gcloud命令:
gcloud compute instances describe <vm-name> --zone europe-west --format='get(networkInterfaces[0].accessConfigs[0].natIP)'
Run Code Online (Sandbox Code Playgroud)
然后我有这个ssh config文件:
Host MyHost
ProxyCommand ~/.ssh/vm-connect
Run Code Online (Sandbox Code Playgroud)
vm-connect它指向具有以下内容的脚本
#!/bin/bash
get_host() {
gcloud compute instances describe <vm-name> --zone europe-west1-b --format='get(networkInterfaces[0].accessConfigs[0].natIP)'
}
ssh minikf@$(get_host)
Run Code Online (Sandbox Code Playgroud)
如果我只运行脚本,它就会成功连接到虚拟机。但如果我运行ssh MyHost它会给我:
Pseudo-terminal will not be allocated because stdin is not a terminal.
-bash: line 1: SSH-2.0-OpenSSH_8.2p1: command not found
Run Code Online (Sandbox Code Playgroud) 编辑:我见过这种方法有效的情况和无效的情况,我不确定我何时/为何这样做。
假设我有一个足够复杂的条目,我在其中指定了多个参数thathost:
Host thathost
ControlMaster auto
ServerAliveInterval 8
ConnectTimeout 8
Hostname 192.168.5.1
User mememe
ProxyJump thejumpbox
Run Code Online (Sandbox Code Playgroud)
我想在创建其他条目时重新使用此定义,通过添加或覆盖某些配置来提供不同的功能。特别指定备用端口(不,我不想在命令行上使用它)。
理想情况下我能够做类似的事情
Host theirhost
Hostname thathost
User themthem
Run Code Online (Sandbox Code Playgroud)
或者
Host my-remote-serialport
Hostname thathost
RequestTTY yes
RemoteCommand some-script-that-launches-kermit-on-a-specific-dev-tty
Run Code Online (Sandbox Code Playgroud)
或者
Host my-remote-serialport
Hostname thathost
Port 3004
Run Code Online (Sandbox Code Playgroud)
我严格要求根据另一台现有主机来指定一台主机,我不想修改我的Host条目以匹配某些模式“技巧”。
显然,我可以利用ProxyCommand ssh -q nc thathost...or ProxyJump thathost+Hostname localhost后跟所有其他覆盖(对于端口覆盖来说,会将其传递给nc),但这既丑陋又浪费(额外的会话) - 请不要回答这个问题。
对我来说,这是 的缺失功能ssh-config,但也许我看起来不够仔细。
我有以下文件,它是 ssh 的配置文件。
Host vps2 # Linode
HostName xxx.xx.xx.xxx
User foo_user
Host vps3 # Vultr
HostName xxx.xx.xx.xxx
User foo_user
Host vps4
HostName xxx.xx.xx.xxx
User foo_user
Host vps5
HostName xxx.xx.xx.xxx
User foo_user
Host vps6
HostName xxx.xx.xx.xxx
User foo_user
Host vps7 # DigitalOcean
HostName xxx.xx.xx.xxx
User foo_user
Host vps8 # GCP
HostName xxx.xx.xx.xxx
User foo_user
Host pi
HostName xxx.xx.xx.xxx
User pi
# OLD SHALL NOT BE USED
Host vps13
HostName xxx.xx.xx.xxx
User foo_user
Host vps14-old
HostName xxx.xx.xx.xxx
User foo_user
Host vps4-old
HostName …Run Code Online (Sandbox Code Playgroud) ssh-config ×8
ssh ×7
awk ×2
bash ×2
bitbucket ×1
git ×1
grep ×1
openssh ×1
parsing ×1
sed ×1
shell ×1
ssh-keygen ×1
ssh-tunnel ×1
unknown-host ×1