shiraz73
shiraz73

Reputation: 1

How to escape a # username in ~/.ssh/config file

I am on macos monterey & have the following in my ~/.ssh/config:

Host foo
  HostName cyberark.company.com
  User user@user#company.com@target_vm

ssh foo from my terminal has #company.com@target_vm portion of my User value automatically truncated where as ssh user@user#company.com@[email protected] works correctly. Seems like everything after # is treated as comments in .ssh/config file. How do I escape # in this file?

Upvotes: 0

Views: 627

Answers (1)

Bleacks
Bleacks

Reputation: 41

From SSH Config documentation the character # is a special character interpreted by ssh:

Empty lines and lines starting with '#' are comments.

You can prevent these behavior from happening by telling explicitly ssh to read litteral characters instead of interpreting them:

  • using backslash escape character \ special characters such as # and @ (more informations here)
  • flanking the whole string with quotes '

As mentioned in this answer from Martin Prikryl

Here you may want to try the following in your case:

Host foo
  HostName cyberark.company.com
  User 'user@user#company.com@target_vm'

or using backslash:

Host foo
  HostName cyberark.company.com
  User user\@user\#company.com\@target_vm

Upvotes: 0

Related Questions