
adduseryou'll be prompted for the login name of a user. It is standard practice to use the first letter of the name and the last name. However, just because it's standard practice, doesn't mean you have to do it. If you're working in a small organization, feel free to use
adduser susanto add a user named Susan Johnson. It would make more sense to use
adduser sjohnsonto take into account the fact that your company could hire another person named Susan at some point. Other things to take into account are:
useradd -D
GROUP=100
GROUP=100If you looked at /etc/group, which lists the names of the groups on your system, you'll find number 100 as being assigned to users. This is a default, catch-all group of sorts, that includes all users.
HOME=/homeAs you already know, a user added to the system will be given a directory to keep his or her files. This is created, by default, in /home.
INACTIVE=-1refers to the number of days it takes for the system to lock you out when your account expires. As you can see here, you get locked out real soon!
EXPIRE=refers to a date when your account is supposed to expire. In our example, there is no date. This is probably fine for regular employees, but if you hired some outside consultant to do work for you, you might want to his or her account to expire at the conclusion of business. The best way to handle temporary workers (and especially fired employees) is to delete the account entirely. But even the best administrators are often over-worked and may forget, so setting an expiration date will ensure that an account cannot be used.
SHELL=/bin/bashrefers to the shell that users will have to run commands on the system. Bash, or the Bourne Again Shell, is standard on Linux distributions. That doesn't mean that you as a system administrator can't install other shells on the system and make them the default (The Korn shell, for example). The last item is very important for you as an administrator.
SKEL=/etc/skelmeans that the files located in /etc/skel will be copied to the users directory when you create the account.
alias cp='cp -p -i'
PS1='[?33[45m][?33[1;33m][@]u@h:W >[?33[0m] '
useradd -c "William Shakespeare - AKA, The Bard" -d /home/wshakespeare -m -k /etc/skel -g 100 -s /bin/bash wshakespeare
Q37spqpXAsl1Y
jsmith:F54spqpRAsl1X:12043:0:99999:7:::in /etc/shadow. This is because the password has been created as an md5 hash, which is an encryption algorithm. So, the bottom line here is that you have two options. An administrator that simply needs to add an account here and there can use the options above, minus the -p and then run
passwd userand provide a password. passwd will then create the md5 hash automatically. If you found yourself needing to create many users at the same time, you might want to look into some tools that create these hashes beforehand and then you can provide them with the -p option.
userdel wshakespearewhere you substitute the wshakespeare with the username you wish to delete.
userdel -r wshakespearewhich would remove everything, including his email. We may not want to do this, however. Many people leave leave their employment but their work remains property of the company because of contractual obligations. In this case, we would obviously want to keep the user's files until they could be looked at, copied to another user's account or stored. So be very careful with the -r option.
ls -l todo_list
-rw-r-r- 1 bob users 155 Mar 26 12:33 todo_list
-rwxr-r- 1 bob users 95 Mar 26 12:38 backup_work
chmod o-r todo_listwhich is the more literal way of doing it. As you can see, we have set others (o) minus (-) read (r) for the file.
chmod 640 todo_listif you used the -c option, you could also get a brief explanation of what you did.
chmod -c 640 todo_list
chmod u+x backup_workwhich literally adds (u+x) permission to execute for the owner. We could also user our number system:
chmod 744 backup_workand assign execute permissions for the owner. That is, read (4) + write (2) + execute (1) equals (7) plus read (4) for the group and read (4) for others.
chmod 1777 jack
touch pail_of_water
chmod 0777 jilland create another file:
touch up_the_hill
rm pail_of_waterYou get the proverbial door slammed in your face.
rm: cannot unlink `pail_of_water': Operation not permittedThat file is "stuck" in that directory until only the owner decides to delete it, hence the term sticky. If you've created some directory for others to write to (you're working on project with others, for example), it's always a good idea to set the sticky bit. That way, only you are responsible for making mistakes.
ln -s .mozilla/bob/k4til3zu.slt/bookmarks.html mozilla_bookmarks.html
lrwxrwxrwx 1 bob users 41 Dec 22 16:29 mozilla_bookmarks.html -> .mozilla/bob/k4til3zu.slt/bookmarks.html
chown bob:users log_20030226
find . -name ".saves*" -print -exec rm -f {} ; This finds any file named '.saves' at the end and passes it to the rm command. Again, as with anything that uses the -f (force) option, you should be extremely careful with this. If you were just looking for tilde files, it would be advisable to do it by directory:find /work -name "*~" -print -exec rm -f {} ; find /home -name "*.mp3" -print -exec rm -f {} ; would only eliminate these files from users' directories in /home.