Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

If I use pubkey auth from e.g.: an Ubuntu 11.04 how can I set the ssh client to use only password auth to a server? (just needed because of testing passwords on a server, where I default log in with key)

I found a way:

mv ~/.ssh/id_rsa ~/.ssh/id_rsa.backup
mv ~/.ssh/id_rsa.pub ~/.ssh/id_rsa.pub.backup

and now I get prompted for password, but are there any offical ways?

share|improve this question
up vote 154 down vote accepted

I recently needed this too, and came up with this:

ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no example.com
share|improve this answer
3  
I needed to enforce the password prompt to appear in an environment where Kerberos was used for automated authentication, and a similar command worked for me in that specific situation: ssh -o GSSAPIAuthentication=no example.com – IllvilJa Aug 13 '13 at 10:56

I've discovered a shortcut for this purpose:

ssh user:@example.com

Note the colon (:) and the empty password after it.

share|improve this answer
    
Very nice trick – Anthon Apr 13 '14 at 21:11
1  
No documentation yet. Actually, I've skimmed through the OpenSSH source code to no avail (its parsing stage is rather cryptic and it's morning here :)). My initial motivation: many clients prompt for a password if you give an empty password, e.g. mysql -u user -p – Halil Özgür Apr 14 '14 at 2:38
6  
This does not seem to work anymore, at least not in my case. ssh client was blindly trying unrelated private keys to authenticate to a newly installed server and keep in being rejected due to the maximum amount of tries being reached without ever asking for the password. In order to force password authentication for this first connection, I had to to use -o PreferredAuthentications=password syntax, the colon trick having no noticeable effect. So while this trick may be worth to try, one should not rely on it as a consistent behavior. – WhiteWinterWolf Jun 13 '15 at 6:26
1  
@HalilÖzgür: Sad news, it was a lot easier to remember and to type ;) ! – WhiteWinterWolf Jun 13 '15 at 12:53
1  
@Qualcuno as WhiteWinterWolf said, it doesn't work on some platforms anymore, unfortunately. – Halil Özgür Jan 17 at 23:04

As well as the method posted by scoopr, you can set per host options in your ssh client configuration file.

In your .ssh directory, create a file called config (if it doesn't already exist) and set the permissions to 600, you can then create sections which start with

host <some hostname or pattern>

and then set per host options after that, for example,

host bob.specific.foo
user fred

host *.home.example
user billy
port 9191

so you could have

host server.to.test
PubkeyAuthentication=no

in that file, and then simply

ssh server.to.test

and the option will get picked up.

share|improve this answer

@scoopr and @Halil Özgür answers didn't work for me.

This worked for me:

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no user@example.com

Source: http://linuxcommando.blogspot.com/2008/10/how-to-disable-ssh-host-key-checking.html

share|improve this answer
4  
The question is about client authentication by password. This answer is about checking if the servers host key matches one in known hosts. In effect it is answering a different question – Anigel Sep 3 '15 at 10:48

I recently needed this but none of the options above worked, ssh -v showed that the command-line options passed via the -o switch were over-ridden by the values specified in my ~/.ssh/config file.

What worked was this:

ssh -F /dev/null <username>@<host>

From the ssh man page:

 -F configfile
     Specifies an alternative per-user configuration file.  If a
     configuration file is given on the command line, the system-wide
     configuration file (/etc/ssh/ssh_config) will be ignored. The default 
     for the per-user configuration file is ~/.ssh/config.

Credits to this answer: How can I make ssh ignore .ssh/config?

share|improve this answer
    
this does not answer the question. You can always have the keys stored in agent and your approach will not prevent client from using them. – Jakuje Jan 22 at 15:46
    
Hm, how would one remediate that issue as well as the one I mentioned in my answer? – adeelx Jan 22 at 15:49
    
Also if you have the keys in standard location (as in the question), they will be used regardless the config is present or not. I would go with one of the methods mentioned in the first answers. – Jakuje Jan 22 at 15:54
    
Not quite true, I just tested it out on my Lubuntu 14.04 and even though I have my keys in the standard location ~/.ssh/config, the keys don't get used if I specify -F /dev/null. ssh -v output helps in this case, it clearly shows that because I have a catch-all entry in my ssh config for *, it elects to use the public key rather than respect the options passed via the -o switch as in the former answers. – adeelx Jan 22 at 15:58
    
Standard location is ~/.ssh/id_rsa as stated in manual page. These paths are hardcoded in the client. Just make sure you provide the correct user when testing. – Jakuje Jan 22 at 16:02

I may be the only one in the world with this issue, but I had an ssh from another operating system running (choco ssh in Windows in a cygwin shell) seen via which ssh

So the solution was to

 /usr/bin/ssh user@example.com

Note the full path. I did this after I had run cyg-get openssh

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.