Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Nov 12 '10 at 22:38

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

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 '10 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 '10 at 1:58

2 Answers 2

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.

share|improve this answer
    
@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). –  Gilles Nov 12 '10 at 22:52

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?

share|improve this answer

Your Answer

 
discard

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