2

Is there a way to set the minimum size accepted by sshd as an RSA public key?

I want to restrict users to using RSA keys that are generated with ssh-keygen -b 8196 or greater.

I didn't see any option in sshd_config. There is a ServerKeyBits option, but that seems to apply only for SSHv1.

2
  • 2
    8000 bit minimum? Aren't you slightly overdoing it? If you're using 2000 bits or more it's very unlikely that the keylength is the critical part of your security. Implementation faults are much more dangerous.
    – CodeInChaos
    Nov 11, 2010 at 22:00
  • Yes - and don't forget - this is only the number of bits for the public/private keypair. The actual data stream is only encrypted with something like AES-128 or AES-256, maximum.
    – Brad
    Nov 12, 2010 at 1:58

4 Answers 4

2

In modern sshd versions (newer than when the question was asked), you can use an AuthorizedKeysCommand to fetch the user's public keys. The usual reason to use this, is to fetch keys from some central storage (ldap, mysql...). But you can also use this to filter the user's keys. You should also set AuthorizedKeys file to none to avoid a fallback to the unfiltered keys.

1

I'm going to agree with both CodeInChaos and Brad here. They make some valid points about the questionable approach you're taking to making ssh secure.

Be that as it may, you could look into PAM. If you inspect /etc/pam.d/sshd, you can see which security modules sshd uses. You could write your own module to ensure that the public RSA key used for authentication was generated using 8196 bits, and then place the module in /lib/security. Then add a line into /etc/pam.d/sshd that looks like this:

account required    /lib/security/<my_fancy_security>.so

I'll admit that I'm not sure what mechanism you would use to check the key used. For example, you could try checking the character length of the public key being used. On my machine, generating a public-private rsa pair of keys always produces a public key 1424 characters in length and a private key of 6446 characters in length. Simlarly, generating an rsa key with 2048 bits always produces a public key with 400 characters and a private key with 1766 characters. Note that this seems to be OS-dependent; my laptop produces keys of different lengths. That's not an insignificant limitation.

That's the best I can think of right off. If sshd doesn't provide a solution for you, you might need to get creative and start coding.

1
  • @Ichimonji10: Is there really a way to do this through PAM? As far as I can tell, no PAM module has access to the key used for authentication (auth modules aren't used for public key authentication, and account modules don't know about authentication anyway). Nov 12, 2010 at 22:52
1

8196 ?!?!?

I haven't tried it myself but maybe, compiling from source after modifying ssh.h :

/* Minimum modulus size (n) for RSA keys. */
#define SSH_RSA_MINIMUM_MODULUS_SIZE    768

to your desired modulus size?

0

OpenSSH 9.1 provides a RequiredRSASize config option, see man 5 sshd_config for details:

RequiredRSASize

Specifies the minimum RSA key size (in bits) that sshd(8) will accept. User and host-based authentication keys smaller than this limit will be refused. The default is 1024 bits. Note that this limit may only be raised from the default.

You must log in to answer this question.