![]() |
|
||||
![]()
Intro
This guide is written for sysadmins who wish to exert more influence over the passwords their users are able to choose. There is a FreeBSD (7.0, to be exact) section and a GNU/Linux (CentOS 4.6, to be exact) section. Other operating systems / versions that utilize PAM should be able to take advantage of the same – or very similar – approaches. Be sure to test on your OS / version to confirm it is behaving as you'd expect. This short guide was inspired by some of the thoughtful commentary in the “Hardening FreeBSD” thread, starting from this post. ----------------------------------------- A word on PAM In a nutshell, PAM (pluggable authentication modules) is a series of libraries that provide an API to assist with authentication for services. The general idea is that PAM provides customizable authentication – which is exactly what this guide will take advantage of. An in depth discussion of PAM is well beyond the scope of this guide. I'd recommend a visit to google, wikipedia, and/or the documentation on your system, as you prefer. Note that FreeBSD uses OpenPAM by default, and CentOS uses Linux-PAM by default. The differences between the two are not important for the purposes of this guide. ----------------------------------------- FreeBSD: easy tweaks to enforce better passwords Here we'll take advantage of the powerful pam_passwdqc module. Edit the /etc/pam.d/passwd file, and change this: Code:
#password requisite pam_passwdqc.so enforce=users password required pam_unix.so no_warn try_first_pass nullok Code:
password requisite pam_passwdqc.so enforce=users password required pam_unix.so no_warn try_first_pass nullok That's it. Seriously. Ok, if you want to actually customize pam_passwdqc's behavior there are a few more steps. From the manpages for pam_passwdqc(8): Quote:
Code:
password requisite pam_passwdqc.so min=disabled,disabled,disabled,12,10 similar=deny retry=3 enforce=users password required pam_unix.so no_warn try_first_pass nullok For much more information on the PAM file layouts and pam_passwdqc in particular, it's important to read the manpages: CentOS: tweaks to enforce better passwords Here we'll take advantage of the powerful, underrated, and rather poorly documented pam_cracklib module. (NB: pam_passwdqc is also available on CentOS, and could be used in a fashion similar to what we used for FreeBSD.) Like some things in the Linux world, this isn't quite as neat and tidy as our FreeBSD solution. No offense intended; this is still very much workable, just a bit of a hack to preserve our settings. Edit the /etc/pam.d/system-auth file (which /etc/pam.d/passwd recurses to), and change this line: Code:
password requisite /lib/security/$ISA/pam_cracklib.so retry=3 Code:
password requisite /lib/security/$ISA/pam_cracklib.so minlen=12 lcredit=-2 ucredit=-1 dcredit=-1 ocredit=-2 retry=3 The kernel.org entry on pam_cracklib describes it this way: Quote:
Take the time to read through the pam_cracklib reference cited above. It actually performs a number of intelligent checks before it even reaches the minlength and credit rules, to ensure that users are not providing easily guessable passwords. Now for the hack job. On CentOS, you may want to make your /etc/pam.d/system-auth file system immutable (or perhaps instead modify /etc/pam.d/passwd directly such that it does not recurse). Without doing so you run the risk of having your customization overwritten by programs that write to system-auth. ----------------------------------------- Closing / call for feedback This concludes our brief guide on enforcing better passwords using PAM. This is quite a broad and complex subject, so I'd like to encourage any corrections and related additions (e.g. how to require a password change for new or existing users!).
__________________
Kill your t.v. |
|
|||
![]()
Good looking guide, anomie.
In terms of requiring password change for new/existing users, I can write up on this tomorrow as this is something I do every now and then. I've got the next few days off, so I've got a bit of time. Unfortunately I'm much too tired right now ![]()
__________________
I just saved a bunch of money on my car insurance by fleeing the scene of the accident! |
|
|||
![]()
I can't speak to the ability to do this on CentOS or any other Linux for that matter, but as promised, I'm going to show you how to quickly and easily force a password change on your users of your FreeBSD system.
Let's say you just came across this guide, and you set up your password requirements. Great! But doing this won't require your users to change their passwords to be compliant. So how would you go about doing this? The quick and easy way is to set the "change" date on the user's password. There are a few different ways to do this, and I'll touch on each way. The first way is by using the chsh command. The syntax is: Code:
# chsh <username> Code:
Changing user information for testuser. Login: testuser Password: (REMOVED) Uid [#]: 10002 Gid [# or name]: 9999 Change [month day year]: Expire [month day year]: Class: default Home directory: /home/testuser Shell: /usr/local/bin/bash Full Name: Test User Office Location: Office Phone: Home Phone: Other information: Now, the other option is to use FreeBSD's "pw" command. The syntax is: Code:
# pw usermod -p 23-Jun-2008 <username> Code:
<excerpt> -e date Set the account's expiration date. Format of the date is either a UNIX time in decimal, or a date in `dd-mmm-yy[yy]' format, where dd is the day, mmm is the month, either in numeric or alphabetic format ('Jan', 'Feb', etc) and year is either a two or four digit year. This option also accepts a relative date in the form `+n[mhdwoy]' where `n' is a decimal, octal (leading 0) or hexadecimal (leading 0x) digit followed by the number of Minutes, Hours, Days, Weeks, Months or Years from the current date at which the expiration date is to be set. -p date Set the account's password expiration date. This field is similar to the account expiration date option, except that it applies to forced password changes. This is set in the same manner as the -e option. </excerpt> ![]() Now, that is all well and good, but what if your users never log out? In the real world, this may actually never be possible (dropped network connections, etc), however I thought I'd throw in this little extra tidbit: Forcing a logout on one of your users. It's quite simple really: Code:
# pkill -KILL -u <username> Comments/fixes/concerns/questions/etc are of course welcome ![]()
__________________
I just saved a bunch of money on my car insurance by fleeing the scene of the accident! |
|
|||
![]()
I was going to post my way of forcing (new) users to change their password, but unfortunatly canjunman beat me to it. I will post it anyway, since I have a few nice extras
![]() Also, while writing this, I have found the reason why I also had the pam_passwdqc line in /etc/pam.d/sshd and not just in /etc/pam.d/passwd (see the forum thread anomie referred to). More about that below! Okay, so let's start with some basics: * your basic forced password change: Like canjunman said, this is easiest with pw(8). Code:
pw usermod <user> -p 0-0-0 ![]() * what if a user forgot his password and you want to email him a new one? You can quickly set a new random password, that will expire at first login, with: Code:
pw usermod <user> -p 0-0-0 -w random But how can you easily make all this apply to a new user? That's where /etc/adduser.conf comes into play! Let's set it up so adduser(8) creates a user with a random, expired password by default! First run Code:
adduser -C Use password-based authentication? yes Use an empty password? no Use a random password? yes After all questions are answered you will be asked to confirm the default setup, review and say 'yes'. Your changes will be saved in /etc/adduser.conf Next up, open /etc/adduser.conf - yes this has to be done manually - and add the line: Code:
upwexpire=0-0-0 One thing you might notice is that, when logging in the first time via ssh you are indeed forced to change your password, but no quality check is performed on it! That's why you also need the pam_passwdqc line in /etc/pam.d/sshd! Put it in so the last lines look like this: Code:
# password #password sufficient pam_krb5.so no_warn try_first_pass password requisite pam_passwdqc.so enforce=everyone min=disabled,8,8,8,8 password required pam_unix.so no_warn try_first_pass Voil*, that's it! |
|
|||
![]()
Thank you hopla, with your information above I verified that with a new ssh connection, and without adding passwdqc in sshd, the new rules are not enforced.
Serves me right for trying my setting by using "login" from an already connected session. ![]()
__________________
I just saved a bunch of money on my car insurance by fleeing the scene of the accident! |
|
|||
![]()
Also, the pam_passwdqc(8) man page might come in handy as well
![]()
__________________
I just saved a bunch of money on my car insurance by fleeing the scene of the accident! |
|
|||
![]()
Another dilemma. This is on a 7.1-PRERELEASE.
I added the following line to my /etc/pam.d/sshd file: Code:
password requisite pam_passwdqc.so min=disabled,8,8,8,8 max=40 passphrase=0 similar=permit enforce=users random=0 I set a user's password to be expired, then logged in via ssh, and it asked me to change the password. It even displayed the information about the password restrictions. However, I was able to set the password to something simple and too short (like "aa") and it took it. However, if I try to use passwd to change the password, it won't take it. Again - the exact same line, literally copied and pasted. Any ideas why it won't enforce the restrictions on an ssh login? |
|
|||
![]()
You know what - I answered my own question.
If you set "enforce=users" it will not enforce it... it's treating it like it's root changing their password. If you set "enforce=everyone" then it does enforce it. Granted, enforcing it for root is good to, I guess it's most important to have a secure password for root. Thanks! |
![]() |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Policy routing bsd and cisco | clone | Guides | 1 | 17th August 2009 04:57 PM |
IP Security Policy Management snap-in | wesley | OpenBSD Security | 2 | 11th August 2009 04:34 AM |
A PF packet tagging (policy filtering) question... | Quaxo | OpenBSD Security | 2 | 30th March 2009 10:47 PM |
Set password for Folder | mfaridi | FreeBSD Security | 6 | 5th September 2008 10:49 PM |