685

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?

12 Answers 12

1076

Disable PubkeyAuthentication and also set PreferredAuthentications to password so that alternative methods like gssapi-with-mic aren't used:

ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password  example.com

You need to make sure that the client isn't configured to disallow password authentication.

15
  • 7
    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
    Commented Aug 13, 2013 at 10:56
  • 51
    Nice. Only -o PubkeyAuthentication=no was sufficient in my case.
    – mivk
    Commented Sep 4, 2016 at 10:04
  • 14
    to ssh into a friend osx laptop, I had to use: -o PreferredAuthentications=keyboard-interactive -o PubkeyAuthentication=no instead
    – guido
    Commented Sep 17, 2016 at 15:23
  • 25
    This doesn't work for me. It keeps saying: Permission denied (publickey). and never offers a password prompt. Commented Jul 27, 2018 at 12:18
  • 20
    @reinierpost that's likely because the ssh host has disabled PasswordAuthentication. In fact, I'm here because I wanted to test that disabling password auth worked correctly on my host.
    – RubberDuck
    Commented Sep 8, 2018 at 14:39
261
+50

I've discovered a shortcut for this purpose:

ssh user:@example.com

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

15
  • 2
    Is this documented somewhere? Commented Apr 13, 2014 at 22:23
  • 5
    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 Commented Apr 14, 2014 at 2:38
  • 87
    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. Commented Jun 13, 2015 at 6:26
  • 3
    @Qualcuno as WhiteWinterWolf said, it doesn't work on some platforms anymore, unfortunately. Commented Jan 17, 2016 at 23:04
  • 3
    Make sure that you don't have PasswordAuthentication no on your ssh_config file!
    – Braiam
    Commented Jul 29, 2018 at 22:43
53

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.

5
  • 2
    Thanks for this answer. I created an entry in my ~/.ssh/config and added PubkeyAuthentication no Commented Jun 21, 2018 at 13:55
  • 4
    Doesn't work for me. Commented Jul 27, 2018 at 12:19
  • This solved my issue. Commented Mar 31, 2020 at 10:45
  • 1
    The config actually needs to be PubkeyAuthentication no note that the = sign is not required in ~/.ssh/config file Commented Aug 8, 2020 at 11:53
  • This is what finally worked today! Spent far too much time on other options. I think partially because my server is older and cursed 😂 and I have no clue how I set it up in the past since it doesn't seem to want to honor anything in the authorized_keys on the server.
    – CTS_AE
    Commented Nov 6, 2020 at 20:49
22

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?

7
  • 2
    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
    Commented Jan 22, 2016 at 15:46
  • Hm, how would one remediate that issue as well as the one I mentioned in my answer?
    – adeelx
    Commented Jan 22, 2016 at 15:49
  • 2
    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
    Commented Jan 22, 2016 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
    Commented Jan 22, 2016 at 15:58
  • 1
    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
    Commented Jan 22, 2016 at 16:02
11

I tried a few of these answers, but ssh -v kept showing my public keys getting pulled out of my home directory. However, specifying a bogus identity file did the trick for me:

ssh -i /dev/null host

I have to do this permanently (to work around the broken SSH server in an APC rack-mounted PDU — stay far away from these things if you care about security), so I ended up putting the option into my config file:

Host apc1 apc2
KexAlgorithms +diffie-hellman-group1-sha1
IdentityFile /dev/null
3
  • Permissions 0666 for '/dev/null' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored.
    – rubo77
    Commented Sep 9, 2021 at 17:22
  • This works perfectly and is far easier (both to remember and less typing!) than the top voted answer. Sad how many other answers here are blatantly wrong / out dated.
    – jmc
    Commented Sep 22, 2022 at 11:48
  • 1
    This is great to test if password authentication works (i.e. if you have the right password), despite having a key file locally. So you can test if you can still access the server whenever you lose your key somehow. Commented Sep 30, 2022 at 19:09
9

This is mentioned in a comment above, but I think it deserves to be its own answer.

For people receiving the Permission denied (publickey) error despite the other solutions here, the problem is likely that the server is set not to accept passwords. To change this, you need to get into the server (many services will allow you to access with a password via a virtual console on their management console) and:

  1. nano /etc/ssh/sshd_config

  2. Find PasswordAuthentication no and change it to yes, and uncomment it.

  3. Run sudo service sshd restart (or sudo systemctl restart sshd if using systemd services)

  4. Now try to log in, from a remote server, using one of the methods above, such as ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no example.com

2
  • Nice, from point 1 to 3 worked for me. (Just with small change: sudo systemctl restart sshd) Commented Jan 19, 2021 at 19:36
  • When you look at the output generated by ssh -v you see the following line debug1: Authentications that can continue: publickey,password. If password is missing then none of the client side solutions on this page are going to help you.
    – Martin
    Commented Oct 19, 2023 at 11:12
3

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

This worked for me:

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no [email protected]

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

1
  • 15
    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
    Commented Sep 3, 2015 at 10:48
3

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 [email protected]

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

0
3

A little late to the party but I had to set the ControlPath option to none because I had an already established connection by the means of SSH connection sharing. So authentication was skipped instead of asking for a password. If it's same for you try following command line.

ssh -o ControlPath=none -o PreferredAuthentications=password example.org

1
  • That was it for me: -o PreferredAuthentications=password
    – smichaud
    Commented Dec 20, 2022 at 21:10
2

And also be sure, there is no BatchMode=yes active in .ssh/config. Otherwise you've got no chance, to get an interactive password prompt.

0

I tried just about everything suggested, including setting PasswordAuthentication yes in /etc/ssh/sshd_config on the host, and lots of different arguments to ssh on the client, but still got Permission denied (pubkey).

Then I noticed, in /etc/ssh/sshd_config on the host, the line:

Include /etc/ssh/sshd_config.d/*.conf

and wondered what config that might be pulling in that seemed to be overriding PasswordAuthentication yes. I commented it out (and restarted sshd) - and now I can log in by doing simply ssh user@host!

Both the client and server are DigitalOcean Ubuntu "droplets" (servers), one of which is messed up because of an aborted do-release-upgrade, and I am just trying to migrate the data from the old one (the client) to the new one (the host). Because I only have access to a recovery console on the old server through the web from which I can't copy any text (e.g. a pubkey) and if I try to paste a pubkey into authorized_keys through the web the paste gets screwed up - and I really want to avoid typing in a pubkey by hand! - I have been trying to ssh to the new server using a password rather than a pubkey so found this question. Hopefully I can now start to transfer some data with scp or rsync. But I have had to comment out that Include to do it, which may not be a safe or desirable thing to do in the long term - I just did it to be able to migrate my data. So be careful! But it might help if you're in a similar situation.

1
  • This was exactly the problem I had! Thanks for sharing.
    – cefn
    Commented Apr 22 at 8:12
-1

In my case, I resolved the issue by using -i to specify the private key for the target VM. For example:

ssh -i /path/to/private_key <username>@<vm_ip>
1
  • 1
    This is the opposite of what was asked. The OP has a key but wants to use a password Commented Jan 12, 2023 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .