Attaching a RHEL6 server install to Active Directory for authentication

This guide presumes a clean install of RHEL6.1 with the Basic Server install with no custom packages chosen and the server is registered to RHN already.  This is the basic steps you can take to attach the server to an Active Directory domain.  I also assume that you have a login with the rights to add a workstation to a domain and know how to do that.

First, let’s go ahead and make sure all packages are up to date and install packages needed to configure winbind with the graphical utility, run the following command as root

yum -y update && yum -y install samba-winbind authconfig-gtk xorg-x11-xauth

Second, let’s make sure your clock is in sync with your network’s time server because a skew will cause a domain join to fail.  You can use the following time server if you don’t know your local one.  Run as root:

ntpdate clock.redhat.com

Now, you will want to logout and log back in so that xauth creates the necessary connection to run the graphical utility over ssh.  Then type the following command as root:

authconfig-gtk

AuthConfig

Now, you will want to change User Account Database to Winbind, then set the Winbind Domain to your domain shortname, change Security Model to ads, change Winbind ADS REALM to your domain longname, change Winbind Domain Controllers to your domain controllers fullnames seperated by commas, change Template Shell to the shell you want your users to have, and finally click Join Domain where you will be prompted for your Domain administrator login and password.  Click OK after filling out the login information.

If all goes well, you should see Joined ‘HOSTNAME’ to realm ‘DOMAIN LONGNAME’ and maybe a DNS update failed! message after that.  You can ignore the DNS error though.

AdvanceOption

Next click over to the Advanced Options tab and check “Create home directories on the first login” to have home directories automatically generated with the contents of /etc/skel when users login for the first time.  Otherwise, you will need to pre-create all the home directories, and that isn’t terribly fun if you have more than like 5 users.  After that, click Apply and the window should close.  You might also see some Gtk-Message errors, but those are nothing to worry about either as they are just libraries to open different window themes.

Okay, so to test the Winbind connection is up and working, let’s run the next couple of commands as root.

net ads testjoin

The result should be “Join is OK”

wbinfo -u

This command may take a few minutes to return if you have a lot of users in your domain.  But it should eventually return with a list of all the users in your domain.  If that comes back the way we expect, then next we will try logging in with a user.

ssh aduser@MYDOMAIN@localhost

Right now, all your logins have your domain as part of the login name, your login actually looks like MYDOMAIN\aduser.  It’s really just one in the middle, but you need the second one to tell the shell that the is a literal .  Anyways, it should prompt you for your password and you should be able to login and have your home directory automatically created at /home/MYDOMAIN/aduser, you can test by typing pwd.  You can also test that groups is working by just typing groups to see what groups you are a member of.  You can stop here if you are happy with the way everything is.

Extra Settings for different options:

Now, I will share some extra settings for RHEL6 because the default options are honestly annoying for you and your users trying to log into the server.

Pull UID/GID Numbers from ad instead of local database

Be default, Samba/Winbind authentication is setup to generate it’s own database of UID/GID numbers for users and groups.  If you are setting up a group of computers that mount a shared filesystem and you want to make sure that all users and groups on each workstation have the same UID/GID.  You can change some settings to have those numbers pulled from AD instead of generated locally.  To fix this, we make changes in the /etc/samba/smb.conf file

Below are the settings configured by system-config-authentication:

idmap uid = 16777216-33554431
idmap gid = 16777216-33554431

Here is what I replace them with to get UID/GID numbers pulled from AD.  Change MYDOMAIN to your domain shortname.

idmap backend = idmap_rid:MYDOMAIN=1000-9000000
idmap uid = 1000-9000000
idmap gid = 1000-9000000

After applying that conf change, do the following to clean out the winbind local database caches.

service winbind stop && rm -f /var/lib/samba/*.tdb && service winbind start

remove domain name from username/login and change home directory location

To fix your login names from being something like MYDOMAIN\mylogin or mylogin@MYDOMAIN and instead have it just be mylogin, you will need to change a setting in the /etc/samba/smb.conf file.  Below is the setting and it defaults to false, you just have to change it to true.

winbind use default domain = true

Another helpful setting is the one below for changing the default location where home directories are created.  By default, they are created as /home/DOMAIN/username, this is best added in /etc/samba/smb.conf above the template shell line.

template homedir = /home/%U
Advertisement
Posted in Uncategorized | Tagged , , , , , | 3 Comments

Attaching Fedora 16 to an Active Directory domain for logins

After a couple of days spent figuring out what was missing in terms of packages and configuration stuff.  I finally got my test workstation talking to the Active Directory at the location I work at.  It was a bit tricky because a few settings have changed with the newer version of Samba that were very different from the settings I use with RHEL5/6.

First, this assumes that selinux is off, and it also assumes that all updates are applied.  Outside of that, this is with a basic Desktop install of Fedora 16.

Some extra packages need to be installed that aren’t installed by default, use the following command for that:

yum -y install samba-winbind samba samba-winbind-krb5-locator

Next, as root, run the following command

system-config-authentication

Change User Account Database to “Winbind

Winbind Domain = Your Active Directory Domain Short Name, Example: MYDOMAIN

Security Model = ads

Winbind ADS Realm = Your Active Directory Domain Long Name, Example: DS.MYDOMAIN.COM

Winbind Domain Controllers = Your Active Directory Domain Controllers separated by commas, Example: dc1.mydomain.com,dc2.mydomain.com

Template Shell: This is the default shell you want for all domain users, for mine, I choose /bin/bash

If you click over to the Advanced Options tab, you may want to check “Create home directories on the first login

Then click Join Domain, then Save, then type in an AD user that has permissions to join computers to the domain and the password that accompanies that user.  Then click Okay.  Back in the terminal, you should see a message like Joined ‘YOURWORKSTATION’ to realm ‘ds.Mydomain.com’  You may see some DNS Update failed messages after that, but they shouldn’t matter.

To test if your join worked, do the following:

service winbind restart
wbinfo -u

If wbinfo returns nothing, then your join wasn’t fully successful.  You may need to look at /var/log/messages to see if selinux stopped you or something else went wrong.  If wbinfo -u returns a list of users, then you are doing good so far.  You can also test an individual user by typing “id MYDOMAINmyuser”  You should even be able to login with your users via SSH, but we are not quite there yet with logging into Gnome with a domain user.

I found a missing setting(which might be a bug) that prevents you from logging into Gnome using the system-config-authentication tool.  Use the following command as root to add the missing line into the correct file.  *You should backup the file by making a copy of it just in case something goes wrong*

echo "session     required      pam_winbind.so" >> /etc/pam.d/password-auth

After this, you should be able to login to the main screen by choosing “Not Listed” and putting YOURDOMAINlogin for the Username and then your domain password.  If you checked on to auto-create the home directory earlier, that should all happen automatically.  If for some reason, it still doesn’t work, you may want to try a reboot.  During one test while writing this, I had to do that.  During another, it just worked right away.

*THIS APPEARS TO HAVE BEEN FIXED IN AN UPDATE*  After this, I noticed I had an issue where I was not getting my full listing of group memberships.  I found a setting in /etc/nsswitch.conf that wasn’t documented in the man page that fixed this problem.  Took forever to troubleshoot.  There is a new line called initgroups that defaults to just files.  I changed it to the following:

initgroups: files winbind

Extra Settings for different options:

I figured I would add some other useful things that you can do to your configuration that I generally do to make things work better.

Pull UID/GID numbers from AD instead of local database

Be default, Samba/Winbind authentication is setup to generate it’s own database of UID/GID numbers for users and groups.  If you are setting up a group of computers that mount a shared filesystem and you want to make sure that all users and groups on each workstation have the same UID/GID.  You can change some settings to have those numbers pulled from AD instead of generated locally.  To fix this, we make changes in the /etc/samba/smb.conf file

Below are the settings configured by system-config-authentication:

idmap uid = 16777216-33554431
idmap gid = 16777216-33554431

Here is what I replace them with to get UID/GID numbers pulled from AD.

idmap config * : backend = rid
idmap config * : range = 2000-50000000

After applying that conf change, do the following to clean out the winbind local database caches.

service winbind stop && rm -f /var/lib/samba/*.tdb && service winbind start

Remove domain name from username/login and change home directory location

To fix your login names from being something like MYDOMAIN\mylogin or mylogin@MYDOMAIN and instead have it just be mylogin, you will need to change a setting in the /etc/samba/smb.conf file.  Below is the setting and it defaults to false, you just have to change it to true.

winbind use default domain = true

Another helpful setting is the one below for changing the default location where home directories are created.  By default, they are created as /home/DOMAIN/username, this is best added in /etc/samba/smb.conf above the template shell line.

template homedir = /home/%U
Posted in Uncategorized | Tagged , , , , | 6 Comments

Cron job for monthly top 50 directories by space usage

Below is a little cron item I conjured up today to report the top 50 directories sorted by space.  At some point, I may work on fixing it so it only reports bottom level directories.

du -h /exports/projects/ | sort -h -r | head -n 51 > /tmp/topproject.txt && mail -s "Linux Projects Top 50" myemail@mydomain.com < /tmp/topproject.txt
Posted in Uncategorized | Tagged | Leave a comment