大网数据广告活动
服务器运维问答

ssh proxyjump command to config file

· 52CE 我爱测

I use a ssh command for logging into a remote node using an intermediate node via proxyjump. The remote and intermediate nodes are Linux servers, and my client is a Macbook. This command works, and it looks like: ssh -i .ssh/id_f…

问题原文

原帖链接 · vpk · CC BY-SA 4.0

I use a ssh command for logging into a remote node using an intermediate node via proxyjump. The remote and intermediate nodes are Linux servers, and my client is a Macbook. This command works, and it looks like:

ssh -i .ssh/id_file -J user1@jump_node -A -D remote_port user2@remote_node

where I replace jump_node and remote_node with the hostnames of intermediate and remote nodes, and remote_port with the sshd port on remote_node.

My first and main question is: how to make this command into a config section that I can put in my .ssh/config file? I looked at ssh man page and could not get the corresponding config options for -D and -A flags (I guess ForwardAgent yes for -A?). Could someone please explain these flags and how to make a correct config section out of this command?


My other question is less important, but would help me understand what is going on here. This second question is about an error I get when I issue a slightly different command.

Most documentation I read online suggest using a command like this:

ssh -i .ssh/id_file -J user1@jump_node user2@remote_node:remote_port

but when I try this command (both with and without the -A flag), I get the following error:

channel 0: open failed: connect failed: Name or service not known
stdio forwarding failed
kex_exchange_identification: Connection closed by remote host
Connection closed by UNKNOWN port 65535

I could not figure out what this error means and if it has some hints I could use?

已采纳解答

原帖链接 · Nikita Kipriyanov · CC BY-SA 4.0

See man 5 ssh_config:

ForwardAgent yes
IdentityFile .ssh/id_file

Host jump_node
    User user1

Host remote_node
   ProxyJump jump_node
   User user2

and just run ssh remote_node.

You can even build a chain this way, if you also specify (another) ProxyJump for the jump_node too.


The second problem is that ssh user2@remote_node:remote_port is incorrect syntax. The error message states Name or service not known, because it attempted (and failed) to resolve remote_node:remote_port as a host name (yes, with embedded colon), not remote_node as you might expect. Try to run same thing without -J, the error message will be slightly more clear.

I'd interpret this as an attempt to specify a port where SSH server is listening on the remote node; for that, use -p command-line parameter or Port host entry option in a config file.

Also this has nothing in common with the -D command-line switch. And it's argument is not a "remote port". Rather, that switch does entirely different thing, namely, it makes the SSH client to listen on the specified port on the local machine and accept SOCKS connections, and the remote will be used as an exit node. You can, for example, configure it in the local browser, so it will access the internet through the SSH tunnel and third parties (web servers) will see your connections as coming from remote host's IP; nobody will see your "real" IP, except the SSH server (which will see jump server's address in this case, though). To set this in the config, you use DynamicForward option in the config file.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-09-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。