ch-2 Linux Acess
ch-2 Linux Acess
Who is user ?
A user is a person who utilizes a computer or network service. Users of computer systems
and software products generally lack the technical expertise required to fully understand
how they work.
Logging In and Logging Out
To ensure security and organization on a system with many users, Unix machines employ a system of
user accounts. The user accounting features of Unix provide a basis for analysis and control of
system resources, preventing any user from taking up more than his or her share, and preventing
unauthorized people from accessing the system. Every user of a Unix system must get permission by
some access control mechanism.
Logging in
Login:
Type your username at the login prompt, and press the return key. The system will then ask
you for your password. When you type your password, the screen will not display what you
type.
Your username
Your username is assigned by the person who creates your account. At ISU, the standard username
is the first four letters of your last name concatenated with the first four letters of your first name.
Your username must be unique on the system where your account exists since it is the means by
which you are identified on the system.
Your password
When your account is created, a password is assigned. The first thing you should do is
change your password, using the passwd utility. To change your password, type the
command
passwd
after you have logged in. The system will ask for your old password, to prevent someone
else from sneaking up, and changing your password. Then it will ask for your new
password. You will be asked to confirm your new password, to make sure that you didn't
mistype. It is very important that you choose a good password, so that someone else
cannot guess it. Here are some rules for selecting a good password:
Rules of give to the password
•Do not use any part of your name, your spouse's name, your child's name, your pet's
name, or anybody's name. Do not use any backward spellings of any name, either.
•Do not use an easily-guessable number, like your phone number, your social security
number, your address, license plate number, etc.
•Do not use any word that can be found in an English or foreign-language dictionary.
•Do not use all the same letter, or a simple sequence of keys on the keyboard, like qwerty.
•Do use a mix of upper-case and lower-case letters, numbers, and control characters.
If you have accounts on multiple machines, use a different password on each machine. Do
not choose a password that is so difficult to remember that you must write it down.
Logging Out
When you're ready to quit, type the command
exit
Before you leave your terminal, make sure that you see the login prompt, indicating that
you have successfully logged out. If you have left any unresolved processes, the Unix
system will require you to resolve them before it will let you log out. Some shells will
recognize other commands to log you out, like "logout" or even "bye".It is always a good
idea to clear the display before you log out, so that the next user doesn't get a screenful
of information about you, your work, or your user account. You can type the command
clear
right before you log out, or you can press the return key until all the information is
scrolled off the screen.
Types of user add in linux
To add/create a new user, all you’ve to follow the command ‘useradd‘ or ‘adduser‘ with
‘username’. The ‘username’ is a user login name, that is used by user to login into the
system.
Only one user can be added and that username must be unique (different from other
username already exists on the system).
For example, to add a new user called ‘tecmint‘, use the following command.
tecmint:x:504:504:tecmint:/home/tecmint:/bin/bash
The above entry contains a set of seven colon-separated fields, each field has it’s own meaning. Let’s
see what are these fields:
1.Username: User login name used to login into system. It should be between 1 to 32 charcters
long.
2.Password: User password (or x character) stored in /etc/shadow file in encrypted format.
3.User ID (UID): Every user must have a User ID (UID) User Identification Number. By default UID 0
isreserved for root user and UID’s ranging from 1-99 are reserved for other predefined accounts.
Further UID’s ranging from 100-999 are reserved for system accounts and groups.
4.Group ID (GID): The primary Group ID (GID) Group Identification Number stored in /etc/group file.
5.User Info: This field is optional and allow you to define extra information about the user. For
example, user full name. This field is filled by ‘finger’ command.
1.Home Directory: The absolute location of user’s home directory.
2.Shell: The absolute location of a user’s shell i.e. /bin/bash.
By default ‘useradd‘ command creates a user’s home directory under /home directory
with username. Thus, for example, we’ve seen above the default home directory for the
user ‘tecmint‘ is ‘/home/tecmint‘.
However, this action can be changed by using ‘-d‘ option along with the location of new
home directory (i.e. /data/projects). For example, the following command will create a
user ‘anusha‘ with a home directory ‘/data/projects‘.
You can see the user home directory and other user related information like user id, group
id, shell and comments.
anusha:x:505:505::/data/projects:/bin/bash
3. Create a User with Specific User ID
In Linux, every user has its own UID (Unique Identification Number). By default,
whenever we create a new user accounts in Linux, it assigns userid 500, 501, 502 and so
on…
But, we can create user’s with custom userid with ‘-u‘ option. For example, the following
command will create a user ‘navin‘ with custom userid ‘999‘.
Now, let’s verify that the user created with a defined userid (999) using following
command.
navin:x:999:999::/home/navin:/bin/bash
4. Create a User with Specific Group ID
Similarly, every user has its own GID (Group Identification Number). We can create
users with specific group ID’s as well with -g option.
Here in this example, we will add a user ‘tarunika‘ with a
specific UID and GID simultaneously with the help of ‘-u‘ and ‘-g‘ options.
tarunika:x:1000:500::/home/tarunika:/bin/bash
5. Add a User to Multiple Groups
The ‘-G‘ option is used to add a user to additional groups. Each group name is separated by
a comma, with no intervening spaces.
Here in this example, we are adding a user ‘tecmint‘ into multiple groups
like admins, webadmin and developer.
Next, verify that the multiple groups assigned to the user with id command.
uid=1001(tecmint) gid=1001(tecmint)
groups=1001(tecmint),500(admins),501(webadmin),502(developers)
context=root:system_r:unconfined_t:SystemLow-SystemHigh
6. Add a User without Home Directory
In some situations, where we don’t want to assign a home directories for a user’s, due to
some security reasons. In such situation, when a user logs into a system that has just
restarted, its home directory will be root. When such user uses su command, its login
directory will be the previous user home directory.
To create user’s without their home directories, ‘-M‘ is used. For example, the following
command will create a user ‘shilpi‘ without a home directory.
Now, let’s verify that the user is created without home directory, using ls command.
Here in this example, we create a user ‘aparna‘ with account expiry date i.e. 27th April 2014 in YYYY-
MM-DD format.
Next, verify the age of account and password with ‘chage‘ command for user ‘aparna‘ after
setting account expiry date.
The ‘-f‘ argument is used to define the number of days after a password
expires. A value of 0 inactive the user account as soon as the password has
expired. By default, the password expiry value set to -1 means never expire.
Here in this example, we will set a account password expiry date i.e. 45
days on a user ‘tecmint’ using ‘-e‘ and ‘-f‘ options.