Command for SSH with @ in User Name

I am trying to log into a server using SSH through the command line. I understand that the format is sftp -oPort=22 Username@Hostname. My issue is that my user name also has an @ symbol in it. Can someone tell me how I can get the system to not think that the last half of the user name as part of the hostname.

For example, my username is user@name. My hostname is hostname. When putting in the command, I am using sftp -oPort=22 user@name@hostname. The results I am getting is a request for the password for name@hostname.

Any help you can give would be greatly appreciated.

davkatjenn

Did you give a try passing user@name in quote as 'user@quote'

or user\@name@host.name

would suggest you could either try escaping (sdfg\@fgh ) or quoting ('abcd@defg')

but since I'v never come across @ in a username before, out of interest, what OS are you on that allows "@" to be used as such?

:slight_smile:

Usernames are never supposed to contain @, from man useradd:

       Usernames must start with a lower case letter or an underscore,
       followed by lower case letters, digits, underscores, or dashes. They
       can end with a dollar sign. In regular expression terms:
       [a-z_][a-z0-9_-]*[$]?

Many things are written to this spec.

Thank you all for your suggestions. None of them worked. As to the OS question, I do not know the answer.

We found a way to make this work. Just in case anyone would like to know, now or in the future, I will detail what we did. We have tested this for Unix. I don't know how this will effect other systems.

In the .ssh folder on your server, create a file called config.
In that file, type the following:

Host <trading partner name i.e. bookstore>

HostName <actual hostname used for connection>
User <actual user name used for connection>
Port 22

Then, when you login from the command line, type sftp bookstore.
Press enter. The results will be a connection where it will tell ask you for the user@hostname's password.

davkatjenn

1 Like

That's a neat workaround. Have to remember that.

Not sure if this will work, but you can try this as well:

> sftp -oPort=22 user\\@name@hostname

Notice, the double escape... one is for the shell and another for sftp.

1 Like

Just an update to this issue...the script worked to get to the site, but we still had to manually put in the password. We couldn't get the script to continue after it called the .ssh file. The only resolutions we could find is to get the trading partner to change the @ symbol to something else, or to come to us to pick up the file.

Have you tried logging in without a password, with a key?

Create a key, e.g. with command ssh-keygen -t dsa. You'll be prompted for a passphrase.
That creates id_dsa (your secret key) and id_dsa.pub (your public key) in ~/.ssh.
Copy the .pub file to the remote host in your ~/.ssh/authorized_keys file. Create or append.
You may need to set the mode on authorized_keys to 0600.

Now when you log in you'll be prompted for the passphrase to decrypt your secret key.
If you don't want to be prompted everytime, install the keychain package and create a ~/.keychain directory.