8/11/2019 Lec2 Managing Users
1/25
Linux Installation and
Administration
Lesson 2
Tutor: George Papamarkos
8/11/2019 Lec2 Managing Users
2/25
Lesson Outline
Getting help in Linux
Using man command
Shell Prompt Basics Linux Authentication Settings
Working as root
Managing users and groups Getting System Information
Memory/CPU Usage
Disk Usage
8/11/2019 Lec2 Managing Users
3/25
Getting Help
Applications, utilities, and shell prompt commandsusually have corresponding manual pages (also calledman pages)
Man pages show the reader the available options andvalues of file or executable.
Man Pages can be accessed via shell prompt bytyping the command man and the name of the
executable.
E.g. man lsto see the manual page of ls command
8/11/2019 Lec2 Managing Users
4/25
Getting Help (cont.) The NAMEfield shows the executable's
name and a brief explanation of whatfunction the executable performs.
The SYNOPSISfield shows the commonusage of the executable, such as whatoptions are declared and what types of input(such as files or values) the executablesupports.
The DESCRIPTIONfield shows availableoptions and values associated with a file orexecutable. See Also shows related terms,files, and programs.
To navigate the man page you can use the[Page Down]and [Page Up]keys or use
the [Spacebar]to move down one pageand [B]to move up. To exit the man page,type [Q].
To search a man page for keywords type [/]and then a keyword or phrase and press[Enter]. All instances of the keyword will behighlighted throughout the man page,allowing you to quickly read the keyword incontext.
8/11/2019 Lec2 Managing Users
5/25
Shell Prompt Basics
Create a directory
mkdir
Copy a file from one dir to another
cp Make a copy of a file with another name
cp
Move a file
mv
Rename a file
mv
Remove a file
rm
8/11/2019 Lec2 Managing Users
6/25
Shell Prompt Basics (cont.) Determining your current directory by 'pwd' command:
$ pwd
/home/gpapa05
Create a directory with 'mkdir' command
$ mkdir
E.g.mkdir lesson2 Change Directory with 'cd' command
$ cd lesson2
$ pwd
/home/gpapa05/lesson2
8/11/2019 Lec2 Managing Users
7/25
Shell Prompt Basics
(cont.) View directory contents with 'ls' command
The following is a short list of some options commonly used with ls. Remember, youcan view the full list by reading the ls man page (man ls).
-aall. Lists all the files in the directory, including the hidden files (.filename). The ..
and . at the top of your list refer to the parent directory and the current directory,respectively.
-llong. Lists details about contents, including permissions (modes), owner, group,size, creation date, whether the file is a link to somewhere else on the system andwhere its link points.
-F file type. Adds a symbol to the end of each listing. These symbols include / toindicate a directory; @ to indicate a symbolic link to another file; and * to indicate anexecutable file.
-r reverse. Lists the contents of the directory from back to front.
-Rrecursive. This option lists the contents of all directories below the currentdirectory recursively.
-Ssize. Sorts files by their sizes.
8/11/2019 Lec2 Managing Users
8/25
Shell Prompt Basics
(cont.) Linux has a utility which can help you keep short lists, gather lists
together, and even show you information about your system.
The utility is called cat, short for concatenate, which means to combinefiles.
The command cat will also display the contents of an entire file on thescreen (for example, type cat filename.txt). If the file is fairly long, it willquickly scroll past you on the screen. To prevent this, use the catfilename.txt | less command.
The grep command
The grep command is useful for finding specific character strings in a file.
For example, if you want to find every reference made to "coffee" in the filesneakers.txt, you would type:
grep coffee sneakers.txt
8/11/2019 Lec2 Managing Users
9/25
Shell Prompt Basics
(cont.)Pipes and Pagers In Linux, pipes connect the standard output of one command to the
standard input of another command.
E.g. ls -al /etc | less
Redirects the output of the ls command to the less command. (Try itout)
Pipes can also be used to print only certain lines from a file. E.g.
grep coffee sneakers.txt | lpr
This command prints every line in the sneakers.txt file that mentions the word"coffee"
The more command Similar to less command
The main difference between more and less is that less allows backward andforward movement using the arrow keys, while more uses the [Spacebar] andthe [B] key for forward and backward navigation.
8/11/2019 Lec2 Managing Users
10/25
Shell Prompt Basics (cont.) The head command
You can use the head command to look at the beginning of a file. The command is:
head
The tail command
The reverse of head command. Using tail, you can view the last ten lines of a file
Using the -f option, tail automatically print new messages from an open file to the screen in real-time
E.g. tail -f /var/log/messages
Wildcards and Regular Expressions
Using wildcards or regular expressions, you can perform actions on a file or files without knowing thecomplete filename.
Wildcards are special symbols that you can substitute for letters, numbers, and symbols
E.g. ls s*.txtwill result all the files in the current dir that start with s and are suffixed with .txt
Here is a brief list of wildcards and regular expressions:
*Matches all characters
?Matches one character in a string
\*Matches the * character
\?Matches the ? character
\)Matches the ) character
8/11/2019 Lec2 Managing Users
11/25
Create a user account
Creating a user account
You should avoid working in the root account fordaily tasks
In case that you want to perform a task that requiresroot privileges use the command su . You will be
asked to provide the root password. If everythinggoes fine you will get a root prompt
You HAVE TO create a user account to work on
Two ways to create a user
Graphically from User Manager
From a shell prompt
8/11/2019 Lec2 Managing Users
12/25
Create a user account
graphically Click the Start Hereicon on the
desktop. In the new window that opens,click the System Settingsicon, andthen click the Users & Groupsicon. You
can also select Main Menu=> SystemSettings=> Users & Groupsfrom thepanel.
You can also start the User Managerbytyping redhat-config-users at a shellprompt.
If you are not logged in as root, you willbe prompted for your root password.
The User Manager window appears
8/11/2019 Lec2 Managing Users
13/25
Create a user account
graphically (cont.) To add a new user, click theAdd Userbutton. Type the username and full name for the new user
in the appropriate fields
Type the user's password in the PasswordandConfirm Passwordfields. The password must beat least six characters.
Select a login shell. If you are not sure which shellto select, accept the default value of /bin/bash.
The default home directory is /home/username.You can change the home directory that is createdfor the user, or you can choose not to create thehome directory by unselecting Create homedirectory. If you select to create the homedirectory, default configuration files are copied
from the /etc/skeldirectory into the new homedirectory.
To specify a user ID for the user, select Specifyuser ID manually. If the option is not selected,the next available user ID starting with number500 will be assigned to the new user. Red HatLinux reserves user IDs below 500 for systemusers.
Click OKto create the user.
8/11/2019 Lec2 Managing Users
14/25
Create a user from shell
promptTo create a user account from a shell prompt:1. Open a shell prompt.
2. If you are not logged in as root, type the command su and enterthe root password.
3. Type useradd followed by a space and the username for the newaccount you are creating at the command line (for example, useraddjsmith). Press [Enter]. Often, usernames are variations on the user'sname, such as gpapam for George Papamarkos, but the final choice isyours.
4. Type passwd followed by a space and the username again (forexample, passwd jsmith).
5. At the New password: prompt enter a password for the new user andpress [Enter].
6. At the Retype new password: prompt, enter the same password toconfirm your selection.
7. For more options on user creation see man useradd
8/11/2019 Lec2 Managing Users
15/25
Modifying User Properties To view the properties of an existing user, click on the
Userstab, select the user from the user list, and clickPropertiesfrom the button menu
The User Propertieswindow is divided into multipletabbed pages: User DataShows the basic user information
configured when you added the user. Use this tab to
change the user's full name, password, home directory,or login shell.
Account InfoSelect Enable account expirationifyou want the account to expire on a certain date. Enterthe date in the provided fields. Select User account islockedto lock the user account so that the user cannotlog in to the system.
Password InfoThis tab shows the date that theuser's password last changed. To force the user to
change passwords after a certain number of days, selectEnable password expiration. The number of daysbefore the user's password password, the number ofdays before the user is warned to change passwords,and days before the account becomes inactive can alsobe changed.
GroupsSelect the groups that you want the user tobe a member of and the user's primary group.
Command usermod gives the same functionality from
command line
8/11/2019 Lec2 Managing Users
16/25
User Groups
In Linux/Unix systems users areorganised in groups
A group is a smart way to manageauthentication setting in Linux
Each group defines an access policy over
an certain system resource (e.g. cdrom,audio devices etc.)
Each user belongs to a set of groups
8/11/2019 Lec2 Managing Users
17/25
Adding a New Group
graphically In the User & Groups application
To add a new user group, click theAdd Groupbutton
Type the name of the new group tocreate.
To specify a group ID for the newgroup, select Specify group IDmanuallyand select the GID.
Red Hat Linux reserves group IDs
lower than 500 for system groups. Click OKto create the group. The
new group will appear in the grouplist.
8/11/2019 Lec2 Managing Users
18/25
Adding a Group from the
shell prompt To add a group to the system, use the
command groupadd
groupadd The command line options for groupadd are:
Exit with an error if the group already exists. (The group is not altered.) If -g and -fare specified, but the group already exists, the -g option is ignored.
-f
Create a system group with a GID less than 500.-r
Group ID for the group, which must be unique and greater than 499.-g gidDescriptionOption
8/11/2019 Lec2 Managing Users
19/25
Modifying Group
Properties To view the properties of an
existing group, select thegroup from the group listand click Propertiesfrom
the button menu The Group Userstab
displays which users aremembers of the group.
Select additional users to be
added to the group, orunselect users to beremoved from the group
Click OKorApplyto modifythe users in the group.
8/11/2019 Lec2 Managing Users
20/25
Getting system information
System Processes To get information about the processes running on your system
we can use ps command from the shell prompt.
The ps ax (ax are the parameters passed) command displaysa list of current system processes, including processes owned byother users.
To display the owner of the processes along with the processesuse the command ps aux.
The ps output can be long. To prevent it from scrolling off thescreen, you can pipe it through less command:
ps aux | less
You can use the ps command in combination with the grepcommand to see if a process is running. E.g. to see if mozilla isrunning type: ps ax | grep emacs
8/11/2019 Lec2 Managing Users
21/25
Getting system information
System Processes (2) The top command displays currently running processes and
important information about them including their memory andCPU usage.
In contrast to ps command top is interactive and real-time To exit top, press the [q]key.
8/11/2019 Lec2 Managing Users
22/25
Getting system information
System Processes (3) In GNOME and KDE you can use a
Graphic System Monitor as well.
In GNOME for example select MainMenu Button (on the Panel) =>
System Tools=> SystemMonitoror type gnome-system-monitor at a shell prompt fromwithin the X Window System to getthe GNOME System Monitortool
GNOME System Monitor givesyou almost all the facilities providedby top command but graphically
You can enda process, search aprocess by name etc.
8/11/2019 Lec2 Managing Users
23/25
Getting System Information
Memory Usage The free command displays the total amount of physical
memory and swap space for the system as well as the amountof memory that is used, free, shared, in kernel buffers, andcached.
The command free m shows the same information inmegabytes, which are easier to read.
This information can also be taken by getting the contents ofmeminfo file in proc directory. To do so type:
cat /proc/meminfo Graphically you can still use GNOME System Monitor and
select the System Monitor tab
8/11/2019 Lec2 Managing Users
24/25
Getting System Information
Monitor Disks The df command reports the system's disk space usage.
By default, this utility shows the partition size in 1 kilobyte blocks andthe amount of used and available disk space in kilobytes. To view theinformation in megabytes and gigabytes, use the command df h. The
-h argument stands for human-readable format. For more see the appropriate manual page
8/11/2019 Lec2 Managing Users
25/25
Thats all folks !
Thanks a lot for your attention !!