Showing posts with label users. Show all posts
Showing posts with label users. Show all posts

Thursday, February 7, 2008

Creating A New *Nix User

The easiest way to create a new user on the command line is:
sudo useradd george
sudo passwd george


But that's not always enough. Let's say, for instance that you want people to change their password the first time that they log in and then again every three weeks. Let's set georgette up like that:
sudo useradd georgette -c "Georgette Userina"
sudo passwd georgette
(give her a throw-away password)
sudo passwd -e -x 21 georgette


Here's what we just did:
sudo = "superuser do" (do this as if you are root)
add user georgette with the comment (-c) "Georgette Userina" (-c is usually used for the user's full name)
give georgette a password she can use the first time she logs in
expire georgette's password immediately (so she has to change it when she next logs in) and then expire (-x) her password every 21 days.

Need a short term user? Maybe you have a contractor working with your company for a short time or a friend that's hanging out at your house for the next two weeks and needs access to your Ubuntu desktop while he's there. Here's how to do it:
sudo useradd sammi -c "Sammi Shortimer" -e 2008-03-10


Here we use the -e option with useradd to expire the account after March 10, 2008.

If you do most of your new user adds with the same special options, you can set those things as default in the file /etc/login.defs

Sunday, December 9, 2007

Give a user a new group

So, you have someone who just got a new position within your organization and now s/he needs additional permissions on the server. It makes more sense to give people permissions based on their position rather than on their user. That way, you can give and take exactly the right group of permissions for the position based on a well thought out policy rather than a spur of the moment, "I think they need x to get things done today," sort of thing.

A perfect example of this is sudoers privileges. You can give specific root-type abilities to users or groups of users in the /etc/sudoers file. Another example of this is when you make a certain folder owned by a specific group and have people write to it as *themselves.thatGroup.

You want to use usermod to add a new group to a user, but the problem is that when you use -G to add additional groups, it takes the list that you give it and erases whatever was on the list before. The solution is to add -a for append like this:

usermod -G groupname -a username

Now your user won't lose any of the old groups s/he had, but s/he will get the new one that they need.

*NB: There are a couple of notations for username and groupname for ownership on *Nix. One is username.groupname. The other is username:groupname They are often interchangeable on a single OS or distro, but sometimes you can only use one or the other for commands like chown.