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

Is there a way to prevent SSH from lowercasing the hostname?

· 52CE 我爱测

I'm using an SSH config file with a ProxyCommand to hop through a bastion host to my target host. Specifically, the ProxyCommand uses a cloud service CLI that takes the hostname / user / port I originally passed, looks them up in…

问题原文

原帖链接 · data princess · CC BY-SA 4.0

I'm using an SSH config file with a ProxyCommand to hop through a bastion host to my target host. Specifically, the ProxyCommand uses a cloud service CLI that takes the hostname / user / port I originally passed, looks them up in a database, and connects me to the host through their bastion. It essentially looks like this:

Host host-*
  ProxyCommand /bin/the-cli %h %r %p

The problem is that the database of target hostnames is case-sensitive, i.e. host-XyZ, but SSH always turns the hostname I originally entered (%h) into a lowercase string. So the end result is something like:

$ ssh host-XyZ

Bastion service: there are no targets with name 'xyz'

Can I prevent SSH from doing this? I don't see any documentation of where the remote hostname is being converted to lowercase.

已采纳解答

原帖链接 · John Mahowald · CC BY-SA 4.0

Use %n instead. Per ssh_config manual

%n    The original remote hostname, as given on the command line.

OpenSSH lowercases %h, which cannot be disabled.

13f97b228 circa 2014 changed something to do with CanonicalizeHostname and ssh_config parsing. It also does a lowercase on the host string. Presumably to allow case insensitive substitution before resolving names.

DNS is supposed to be more or less case-insensitive, which is why they can away with this.

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

资料来源与适用范围

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

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

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