-->

Understanding Linux File Permissions To Adding A New User

The primary tool used to add new users to your Linux system is useradd. This command provides an easy way to create a new user account and set up the user’s HOME directory structure all at once.

Understanding Linux File Permissions To Adding A New User
Understanding Linux File Permissions To Adding A New User


The useradd command uses a combination of system default values and command line parameters to define a user account. The system defaults are set in the /etc/default/useradd file. To see the system default values used on your Linux distribution, enter the useradd command with the -D parameter:

# /usr/sbin/useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
#
Note
Some Linux distributions place the Linux user and group utilities in the /usr/sbindirectory, which may not be in your PATH environment variable. If that’s the case inyour Linux distribution, either add the directory to your PATH or use the absolute filepath to run it.

The -D parameter shows what defaults the useradd command uses if you don’t specify them in the command line when creating a new user account. This example shows the following default values:


  • The new user is added to a common group with group ID 100. 
  • The new user has a HOME account created in the directory /home/loginname.
  • The account can’t be disabled when the password expires.
  • The new account can’t be set to expire at a set date.
  • The new account uses the bash shell as the default shell.
  • The system copies the contents of the /etc/skel directory to the user’s HOME directory.
  • The system creates a file in the mail directory for the user account to receive mail.

The penultimate value is interesting. The useradd command allows an administrator to create a default HOME directory configuration and then uses that as a template to create the new user’s HOME directory. This allows you to place default files for the system in every new user’s HOME directory automatically. In the Ubuntu Linux system, the /etc/skel directory has the following files:

$ ls -al /etc/skel
total 32
drwxr-xr-x 2 root root 4096 2010-04-29 08:26 .
drwxr-xr-x 135 root root 12288 2010-09-23 18:49 ..
-rw-r—r— 1 root root 220 2010-04-18 21:51 .bash_logout
-rw-r—r— 1 root root 3103 2010-04-18 21:51 .bashrc
-rw-r—r— 1 root root 179 2010-03-26 08:31 examples.desktop
-rw-r—r— 1 root root 675 2010-04-18 21:51 .profile
$

These are the standard startup files for the bash shell environment. The system automatically copies these default files into every user’s HOME directory you create.

You can test this by creating a new user account using the default system parameters and then looking at the HOME directory for the new user:

# useradd -m test
# ls -al /home/test
total 24
drwxr-xr-x 2 test test 4096 2010-09-23 19:01 .
drwxr-xr-x 4 root root 4096 2010-09-23 19:01 ..
-rw-r—r— 1 test test 220 2010-04-18 21:51 .bash_logout
-rw-r—r— 1 test test 3103 2010-04-18 21:51 .bashrc
-rw-r—r— 1 test test 179 2010-03-26 08:31 examples.desktop
-rw-r—r— 1 test test 675 2010-04-18 21:51 .profile
#

By default, the useradd command doesn’t create a HOME directory, but the –m command line option tells it to create the HOME directory. As you can see in the example, the useradd command created the new HOME directory, using the files contained in the /etc/skel directory.

Note
To run the user account administration commands in this chapter, you either need to be logged in as the special root user account or use the sudo command to run the commands as the root user account.

If you want to override a default value or behavior when creating a new user, you can do that with command line parameters. These are shown in Table 7.1 below.


The useradd Command Line Parameters
The useradd Command Line Parameters


As you can see, you can override all the system default values when creating a new user account just by using command line parameters. However, if you find yourself having to override a value all the time, it’s easier to just change the system default value.

You can change the system default new user values by using the -D parameter, along with a parameter representing the value you need to change. These parameters are shown in Table below.


The useradd Change Default Values Parameters
The useradd Change Default Values Parameters


Changing the default values is a snap:

# useradd -D -s /bin/tsch
# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/tsch
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
#

Now, the useradd command uses the tsch shell as the default login shell for all new user accounts you create.

0 Response to "Understanding Linux File Permissions To Adding A New User"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel