I recently ran into an issue where I needed to access a server remotely via ssh terminal command. I was surprised to find out that the syntax I have always used to perform such a task was not working.
The issue as it turns out, is that the server administrator created my username with an ampersand in it. Suppose you have a username of “[email protected]” and the server name is simply “domain.com”. Given the user/server name, to ssh into this server you might want to type something like the following:
ssh [email protected]@domain.com
The above will not work for obvious syntax reasons. The solution is to simply use the -o User option (or through the equivalent User directive found in the client configuration file at ~/.ssh/config), and specify the ip you are connecting to. So, the command that allowed me to connect actually looks something like this:
ssh -o [email protected] 192.168...
This also applies to sftp, scp and sshfs as well. For example, if you wanted to copy a file from the remote server to your local machine and your username has an ampersand, the command would look something like this:
scp -o User=user@domain 192.168.xxx.xxx:\file-to-copy.txt
I should also note, that you can handle this sort of thing in your configuration file too, instead of using -o options, which provides the advantage of also working with tools that call ssh and don’t let you easily pass line options, if at all.