Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When you run ssh without a login_name argument, it automatically uses your local username as the login_name. for example:

cogan@localhost$ ssh myserver
cogan@myserver's password: 

Is there a way to force ssh to prompt for login_name?

share|improve this question

migrated from Nov 12 '11 at 7:07

This question came from our site for professional and enthusiast programmers.

up vote 7 down vote accepted

If you're talking about OpenSSH, the answer is no (you can check the source). As pointed out by @cnicutar, you can use ssh user@host or configure aliases in .ssh/config along the lines of

Host meh
  HostName foo
  User bar

and then ssh meh.

share|improve this answer
This is the answer I was looking for. I'm using ssh in a script, so I can just prompt the user for their name myself before making the call, I just wanted to see if there was a way I could have ssh save me the work. – Cogan Nov 11 '11 at 22:09

Since ssh does not have an option for forcing a username prompt; you can create the following script in your ~/bin directory and name it ssh:


my $user_at_address = $ARGV[0];
my @u_a = split(/@/, $user_at_address);

if (defined $u_a[1])
    if ( $^O == 'linux' )
        exec ("/usr/bin/ssh $u_a[0]\@$u_a[1]");
    if ( $^O == 'solaris' )
        exec ("/usr/local/bin/ssh $u_a[0]\@$u_a[1]");
    print "Enter your username: ";
    my $username = <STDIN>;
    chomp ( $username );
    if ( $^O == 'linux' )
        exec ("/usr/bin/ssh $username\@$u_a[0]");
    if ( $^O == 'solaris' )
        exec ("/usr/local/bin/ssh $username\@$u_a[0]");

Then, make the script executable:

chmod 755 ~/bin/ssh

Make sure you have $HOME/bin in your PATH (put export PATH=$HOME/bin:$PATH in your ~/.bashrc or /etc/bashrc and source ~/.bashrc or source /etc/bashrc).

Then, run it as you would ssh:

[ 12:49 jon@hozbox ~ ]$ ssh localhost
Enter your username: bob
bob@localhost's password:
[ 12:50 bob@hozbox /home/bob ]$
share|improve this answer

I don't think so -- if it were, it would be through .sshconfig

You could try setting User to something illegal to see what it does.

share|improve this answer
I just tried this for fun: [ 12:56 Jonathan@MacBookPro ~ ]$ ssh /dev/null@somehost actually works..: /dev/null@somehost's password: -> Permission denied, please try again.. Of course, in the hosts /var/log/secure it shows sshd[21936]: pam_sepermit(sshd:auth): Cannot determine the user's name and sshd[21936]: pam_succeed_if(sshd:auth): error retrieving information about user. – chown Nov 11 '11 at 20:57

So I was having the same issue. I was using cmd

ssh "IP address"


And it was asking immediately for the password for a user that didn't exist (My computers Name).

really simple fix just use this command instead:

ssh root@"IP address"

ssh root@

You can replace root with any username you want. This will cause the server to prompt you for the password to the username you desire.

share|improve this answer
This does not really answer the question. Besides the method you suggest has already been suggested in another answer four years ago. – kasperd Jan 18 at 17:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.