You are on page 1of 120

LINUX Basic Course

Napoleon Rivera
ALU - DCS UNIX

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Introduction
What is Linux?
The Story of Linux.
How Linux is Built?

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Linux Basic Course


Part 1 - OS Installation RHEL
Part 2 - Basic Commands
Part 3 - User and Group
Administration
Part 4 - Linux Filesystem, Files and
Directories
Part 5 - Help Utilities, User
Password
Part 6 - Sudo
Part 7 - File Permissions and Access
Part 8 - ACL
Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Part 1
OS Installation RHEL

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
Prerequisite:
1. Vmware Workstation Version 8.0
2. RHEL_6.2i386 iso
3. Available disk space 25GB
Note: you can download WMware workstation
installer and RHEL6.2 ISO image from this link.
//RGUIRUELA2/iso

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
1. Select " Install or Upgrade an existing system

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
3. Select SKIP

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
3. Choose Language

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
4. Keyboard mapping

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
5. Select Storage Device

10

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
6. Click yes, discard any data

11

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
7. Type the server name

12

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
8. Choose the correct time zone

13

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
9. Provide the initial root password

14

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
10. Select Create Custom Layout

15

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
11. Use this disk partition pattern for your VM

16

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
12. Click Format

17

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
13. Click on next

18

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
14. Select Desktop and Redhat Enterprise Linux

19

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
15. Click on reboot

20

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
16. Click on Forward

21

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
17. Select yes and click Forward

22

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
17. Select yes and click Forward

23

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
17. Select yes and click Forward

24

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
17. Click Forward

25

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
17. Create non-administrative user (regular user)

26

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
17. Set Time

27

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

OS Installation
17. Login

28

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Part 2
Basic Commands

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

SHELL

Commonly used UNIIX/Linux


Shells:
Bash
Ksh
Csh

USER

Shell

Application

Linux Kernel

Computer Hardware

30

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Bash Shell
Environmental Files
These are the hidden files that define the setup and behavior of the terminal.
In Unix, the filenames have no bash as the prefix.
Filename

Description
Script that is executed upon login.

.
bash_profil
e
.
Script that is executed upon logout.
bash_logout
.
Log file of the commands executed in the terminal
Command
Aliases
bash_histor
alias
- can be useful if you want to create a 'shortcut' to
y
.bashrc
Script executed upon login and where the aliases are normally
option/s.
placed.

a command with

[joseph@localhost ~]$ alias la=ls a

Environmental Variables
env
-displays the environmental variables.

Examples are:
HOSTNAME=localhost.localdomain
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
USER=joseph
HOME=/home/joseph
31 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Bash Shell
History
! - repeat specified command
!! - repeat previous command
^^ - repeat previous command with substitution
[ArrowUp] and [ArrowDown] - scroll through the command history (in bash)
history n command followed by the number of last commands to show
!n execute the nth command
Autocomplete
[Tab][Tab] - prints a list of all available commands. This is just an example of
autocomplete with no restriction on the first letter.
x[Tab][Tab] - prints a list of all available completions for a command, where the
beginning is ``x''

Accesing Virtual Terminals


[Alt][Ctrl][F1] - switch to the first virtual text console
[Alt][Ctrl][Fn] - switch to the nth virtual text console. Typically, there are six on a
Linux PC system.
[Alt][Ctrl][F7] - switch to the first GUI console, if there is one running. If the
graphical console freezes, one can switch to a nongraphical console, kill the
process that is giving problems, and switch back to the graphical console using
this shortcut.
32

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Checking Server informations


Command
uname
uptime
top

33

Description
Checks servers OS, hostname, kernel build, date&time,
architecture etc...
Check servers uptime

free

Displays top CPU process. It can sort the tasks by CPU usage,
memory usage and runtime.
Display memory usage

df

Display system disk space

du

Estimates file space usage

lspci

List pci devices (Processor, VGA controller, audio device, SATA,


Ethernet etc

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Moving around the filesystem


Command

Description

pwd

prints the present working directory

ls

lists the contents of the directory

cd

changes the working directory

File Navigation
/ - root directory
./ - current directory
./command_name
- run a command in the current directory when the current
directory is not on the path
../ - parent directory
~ - home directory

34

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Pathnames

Absolute Pathnames
Absolute is typing the complete pathname (/ is the
reference)
[ionrivera@sandbox]$ cd /etc/yum
[ionrivera@sandbox]$
Brings you to the /etc/yum folder
Relative Pathnames (./)
[ionrivera@sandbox]$ ls
pluginconf.d yum-updatesd.conf
[ionrivera@sandbox]$ cd ./pluginconf.d

The .. - will go one level up in the file system

35

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File viewing and manipulation


Command
mkdir
file
view
cat
touch
cp
mv
rm
rmdir
ln

36

Description
Makes a directory
Determines file type
Displays the content of the file
to concatenate or type the content of the file on screen
Changes file timestamps
Copies files or directories
Moves files or directories. It is also used as renaming tool.
Deletes files or directories
Deletes an empty directory
Makes a link or pointer

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Part 3
User and Group
Administration

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Add a New User


Two Methods:
1. Graphical User Manager Tool
2. Commandline Tool

38

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Add a New User

39

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Add a New User


Add new users from the command-line. Start a terminal window
session (Applications -> Accessories -> Terminal) and at the
command prompt enter a command similar to the following:

useradd m user_name
# useradd m ionrivera

40

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Editing the Properties of a User

The properties of a user may be changed using the same User


Manager tool used to add a user as outlined above.. Work through the
various screens in the User Properties dialog for the selected user and
click on the OK button to apply the changes.

41

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Deleting User
Select the user to be deleted and click on Delete. A confirmation
dialog will appear providing the option to delete the user's home
directory and temporary files. If you wish to proceed, click on
Delete.
A user account may also be deleted from command-line using the
userdel utility:

userdel user_name
It is also possible to remove the user's home directory and
mail spool as part of the deletion process:
userdel -r user_name

42

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Adding new Group


New groups are added either using the User Manager graphical tool, or
by using the groupadd command-line tool.

43

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

User Private Group

Linux uses a user private group ( UPG) scheme, which makes UNIX
groups easier to manage. A user private group is created whenever a
new user is added to the system.
It has the same name as the user for which it was created and that
user is the only member of the user private group.

44

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Adding new Group

To add a group from the command line, use the groupadd


utility.
groupadd group_name

Option

Description

-f, --force

When used with -ggid and gid already exists, groupadd


will choose another unique gid for the group.

-ggid

Group ID for the group, which must be unique and


greater than 499.

-K, --keykey=value

Override /etc/login.defs defaults.

-o, --non-unique

Allow to create groups with duplicate.

-p, --passwordpassword

Use this encrypted password for the new group.

-r

Create a system group with a GID less than 500.

45

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Modifying Group
Using Manager tool to modify groups. Select the System desktop menu
Groups from the Administration sub-menu to launch the Groups
Manager tool.

46

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Modifying Group
To add an existing user to an existing group from the command-line.
usemod G group_name1 user_name
To add an existing user to a number of existing groups.
Usermod G group_name1_group_name2,group_name3 user_name

47

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Deleting Group
A group may be deleted from a system using the groupdel
utility.
groupdel group_name
Note that if the group to be deleted is the primary group for any
user it cannot be deleted. The user must first be deleted, or
assigned a new primary group using the usermod command:
usermod g user_name
groupdel group_name

48

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Password Expiration
To configure password expiration for a user from a shell prompt, run the
following command as root:
chage [options] username
Force immediate password expiration by running the following command
as root:
chage -d 0 username

49

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Password Expiration
Option

Description

-ddays

Specifies the number of days since January 1, 1970


the password was changed.
Specifies the date on which the account is locked, in
the format YYYY-MM-DD. Instead of the date, the
number of days since January 1, 1970 can also be
used.
Specifies the number of inactive days after the
password expiration before locking the account. If
the value is 0, the account is not locked after the
password expires.
Lists current account aging settings.
Specify the minimum number of days after which the
user must change passwords. If the value is 0, the
password does not expire.
Specify the maximum number of days for which the
password is valid. When the number of days
specified by this option plus the number of days
specified with the -d option is less than the current
day, the user must change passwords before using
the account.

-Edate

-Idays

-l
-mdays

-Mdays

-Wdays

50

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Shadow Password
In environments with multiple users, it is very important to use shadow
passwords provided by the shadow-utils package to enhance the
security of system authentication files. For this reason, the installation
program enables shadow passwords by default.
Shadow passwords improve system security by moving encrypted
password hashes from the world-readable /etc/passwd file to
/etc/shadow, which is readable only by the root user.
stoShadow passwords re information about password aging.
Shadow passwords allow the /etc/login.defs file to enforce security
policies.

51

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Creating Groups Directories


System administrators usually create a group for each major project
and assign people to the group when they need to access that project's
files.
With this traditional scheme, file managing is difficult; when someone
creates a file, it is associated with the primary group to which they
belong. When a single person works on multiple projects, it becomes
difficult to associate the right files with the right group. However, with
the UPG scheme, groups are automatically assigned to files created
within a directory with the setgid bit set. The setgid bit makes
managing group projects that share a common directory very simple
because any files a user creates within the directory are owned by the
group which owns the directory.

52

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Creating Groups Directories


Create the /var /myproject directory by typing the following at a shell
prompt:
mkdir -p /var/myproject
Add the myproject group to the system:
groupadd /var/myproject
Associate the contents of the /opt/myproject/ directory with the
myproject group:
chown root:myproject /var/myproject
Allow users to create files within the directory, and set the setgid bit:
chmod 2775 /var/myproject
At this point, all members of the myproject group can create and edit
files in the /var/myproject/ directory without the administrator
having to change file permissions every time users write new files.

53

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Users Groups tools and commands


groupadd
A command to add groups.
grpck
A command to verify the /etc/group file.
groupdel
A command to remove groups.
groupmod A command to modify group membership.
pwck
A command to verify the /etc/passwd and
/etc/shadow files.
pwconv
A tool to convert standard passwords to
shadow passwords.
pwunconv A tool to convert shadow passwords to standard
passwords.
useradd
A command to add users.
userdel
A command to remove users.
usermod
A command to modify users

54

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

User and Groups Files

/etc/passwd
User account information.
/etc/shadow
Secure user account information.
/etc/group
Group account information.
/etc/gshadow
Secure group account information.
/etc/default/useradd
Default values for account creation.
/etc/skel/
Directory containing default files.
/etc/login.defs
Shadow password suite configuration.

55

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Standard Users List


User

UID

GID

Home
Directory

root
bin
daemon
sys
adm
tty
disk
lp
mem
kmem
wheel
cdrom
sync
shutdown
halt
mail
news
uucp
operator

0
1
2
3
4
5
6
7
8
9
10
11

0
1
2
3
4
5
6
7
8
9
10
11
(0)
(0)
(0)
12
13
14
(0)

/root
/bin
/sbin
/var/adm
/var/spool/lpd
/sbin
/sbin
/sbin
/var/spool/mail
/var/spool/news
/var/spool/uucp
/root

56

Shell

Packages

/bin/bash

setup

/sbin/nologin

setup

/sbin/nologin

setup

/bin/bash

setup
setup

setup

setup

/sbin/nologin

setup

setup
setup

setup

udev,MAKEDEV

/bin/sync

setup

/sbin/shutdown
/sbin/halt

setup
setup

/sbin/nologin

setup

/sbin/nologin

setup

/sbin/nologin

setup

/sbin/nologin

setup

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Standard Groups
Group

GID

root
bin
daemon
sys
adm

0
1
2
3
4

tty

disk
lp

6
7

mem

kmem

wheel
mail
uucp

10
12
14

man

15

games

20

gopher

30

video

39

dip

40

ftp

50

57

Members
root
root,
root,
root,
root,

bin, daemon
bin, daemon
bin, adm
adm, daemon

root
daemon, lp

root
mail, postfix
uucp

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

lock

54

Part 4
Linux Filesystems,
Files and Directories

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

59

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

The /etc/fstab file


Fstab is a file that contains the information about the filesystems that
will be mounted in the system.
Example content:
[root@localhost root]# cat /etc/fstab
# device name
num
/dev/mapper/
LABEL=/boot
none
LABEL=/home
none
none
/dev/hda3

60

mount point

fs-type options

dump-freq pass-

/
ext3
defaults
0 1
/boot
ext3
defaults
0 2
/dev/pts
devpts gid=5,mode=620 0 0
/home
ext3
defaults
0 2
/proc
proc
defaults
0 0
/dev/shm
tmpfs defaults
0 0
swap
swap defaults
0 0

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

The /etc/fstab file


Device Name

filesystem partition itself or data source.

Mount Point
filesystem.

where the data is to be attached to the

Filesystem Type -

filesystem type such as ext2, ext3, etc.

Options

mount options to be used.

Dump-freq
Normally set to

adjusts the archiving schedule for the partition.


0 (disable) since dump backup isnt used.

Pass-num
controls the order in which fsck checks the device
for errors at
boot time. The root device should
be 1. Other partitions should
be either 2 (to
check after root) or 0 (to disable checking for the
partition altogether.

61

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

The /etc/fstab file


Commonly used mount options:
defaults
mount the filesystem with the default settings: rw, dev,
exec, auto,
nouser, async
async
all input and output to the filesystem will be done
asynchronously.
An obsolete mounting option since existence of journalling
filesystem
types
auto
filesystem will be mounted upon bootup and with the
mount -a command
dev
interpret character or block device files on the filesystem
exec
permit execution of binaries
noauto
filesystem can only be mounted explicitly (i.e. using the
mount command)
nouser
do not allow ordinary users to mount the filesystem
ro
mount the filesystem as read-only
rw
mount the filesystem as read-write

62

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Common Filesystem Types


ext2 -

developed to overcome limitation of the original ext


filesystem. It doesnt have journaling feature

ext3 ext4 -

it allows journaling

supports huge individual file size and filesystem size.


It can enable disable journaling

vfat - extended DOS filesytem


nfs - network filesystem used to access disks located on
remote computers

smb -

network filesystem that supports the SMB protocol,


used by Windows for Workgroups, Windows NT, and Lan
Manager

63

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Mounting/Unmounting of Filesystems
To Mount:
$ mount t <fstype> <device> <mount point>
e.g. mount t nfs /dev/sda9 /apps
To Unmount:
$ cd /
$ umount <mount point>
e.g. umount /apps
Note: Make sure you are not working on the current mount
directory, otherwise, it would show an error device busy
while unmounting.

64

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Filesystem Tools
mkfs
Syntax:
mkfs t <fstype><device>
Example:
mkfs -t ext2 /dev/sda9
fsck
Syntax:
fsck t <fstype> <device>
Example:
fsck t ext2 /dev/sda9

65

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Filesystem Tools
tune2fs
Syntax:
tune2fs c <numeric> -i <string> <device>
Example:
tune2fs c 120 i 3m /dev/sda9
Where:
-c = maximum mount count
-i = interval between checks
To disable checks:
tune2fs c -1 i 0 /dev/sda9

66

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Files and Directories


Linux Command Symbols

<
Example:
sort < file1.txt
Above, sorts the content of file1.txt

>
Example:
cat file1.txt > file2.txt
Above example, displays the content of file1.txt and redirects its output
to file2.txt

>>
Example:
cat file1.txt >> file2.txt
This displays the content of file1.txt and redirects to file2.txt by
inserting it into next line.

|
67

Example:
ps fax | grep <string>| wc l
Above example, displays the output of ps based on target string and
counts its line number. Command displays the output of the last
command wc -l
Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Files and Directories

68

File and Directory Manipulation


To create a directory: mkdir <directory>
To remove a directory: rm rf or rmdir <directory> (use rf to
recursively and forceably remove a directory)
To change directories: cd <directory_name>
To print current working directory: pwd
To find a file or a directory: find <source_dir> -name
<directory_name/file_name>
List contents of a directory: ls <directory_name>
ls l (lists the long format of directory
information)
$ ls -l
drwxr-xr-x4 cliff user 1024 Jun 18 09:40 dir1
-rw-r--r-- 1 cliff user 767392 Jun 6 14:28 file1
^ ^ ^ ^^^ ^ ^ ^ ^ ^
| | | | | || | | | |
| | | | | owner group size date time name
| | | | number of links to file or directory contents
| | | permissions for world
| | permissions for members of group
| permissions for owner of file: r = read, w = write, x = execute -=no
Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Files and Directories


File and Directory Manipulation
To create an empty file: touch <filename>
To edit a file:
vi <filename>
To copy files :
cpfile1 file2
cpfile(s) dirname
To rename files :
(Unix does not rename, it moves from one filename to another)
mvoldname newname

69

To move files to a different directory.


mvfile directory
mvfile(s) directory
To remove (delete) files:
rmfilename
rmfile1 file2 .. fileN
rm -ffilename- forced removal of a file
rm -ifilename- interactive query before removal
rm -rfilename- recursive delete - dangerous.
rm -rfdir(s) file(s)- recursive force - CAREFUL!!!
Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Files and Directories


File and Directory Manipulation
Viewing Files without Opening
catfilename- concatenates and print. This will print out the contents of
the file to the screen.
catfile1 .. fileN- Concatenate and print. This will concatenate several
files together and print to the screen.
morefilename- displays files one page (screen) at a time. Keeps one
line of text from the previous screen.
less filename opposite of more. Scrolling-up and down is its
advantage.
tail filename outputs the last part of the file.
tail f filename outputs appended data of a file in real-time as the file
grows.
70

tail 100 filename outputs last 100 lines of the file.


Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Part 3: Activity
1. Add a virtual disk into your virtual machine (e.g. 2 GB in size)
2. Format the disk with filesystem type ext3
Commands:
mkfs t ext3 <device>
mkfs.ext3 <device>
3. Mount the disk with mountpoint format (/firstname_lastname)
Command:
mount t ext3 <device> /firstname_lastname
4. Unmount the filesystem. Ran fsck to confirm if there are
inconsistencies. Add it into /etc/fstab to automatically mount during
boot-up.
Command:
umount /firstname_lastname
fsck.ext3 <device>
5. Reboot. Filesystem should be automatically mounted after reboot.
6. After reboot, create 2 directories using names, <firstname>
<lastname> into your mounted directory.
7. After creating the directories, create a file on each directory and put
a content/data into it.
71

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Part 5
Help Utilities
User Password

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Linux Man Pages


man
Syntax:
man [section] command-name

73

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Setting an account password


passwd
Syntax:
passwd [-option] username
Options the can be used:
To lock the account
Syntax:

passwd l <username>

To unlock the account


Syntax:

passwd u <username>

To view the password status of the account


Syntax:
passwd S <username>

74

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Password Aging
Enabling password aging by editing login.defs
cat /etc/login.defs

75

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Password Aging
Edit the /etc/default/useradd
The INACTIVE settings indicate
when to change the account to
inactive after the password has
expired
The EXPIRE setting can set an
explicit expiration date for all new
users in the format YYYY-MM-DD
Note:
The above mention step only affect
newly created user after the
settings has been change. In order
to update existing user setting
please use chage command.
76

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Password Aging
To update the settings for users
that already exist, use the chage
tool
chage -M 60 {username}
This will set username
PASS_MAX_DAYS setting to 60 days
and update the shadow file
accordingly.

How to disable password aging for


an user account
To turn off the password expiration
for an user account, set the
following:
-m 0 will set the minimum
number of days between password
change to 0
-M 99999 will set the maximum
number of days between password
change to 99999
-I -1 (number minus one) will set
the Password inactive to never
-E -1 (number minus one) will set
Account expires to never.

77

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Part 6
Sudo

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

SUDO
Why we need to use sudo
- Elevate user privileges
- Execute commands from another user
- Logging logs sudo executed commands

79

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

SUDO
How to execute sudo
sudo su sudo system-config-network
sudo reboot

80

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

SUDO
Edit /etc/sudoers file
vi /etc/sudoers
-edit manually the /etc/sudoers file
visudo
- vi environment
- checks if there syntax error
Sample checking:
visudo
>>> /etc/sudoers: syntax error near line 22 <<<
What now?

81

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

SUDO

Edit /etc/sudoers file


Defining Command Alias
Cmnd_Alias ALIAS_NAME = command1 command2
Examples:
Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date,
/usr/bin/yum
Cmnd_Alias LOCATE = /usr/bin/updatedb
Cmnd_Alias MYCOMMAND = /sbin/reboot, /sbin/ifconfig

82

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

SUDO
Edit /etc/sudoers file
Defining User Alias
User_Alias ALIAS_NAME = user1, user2
Examples:

##
user
User_Alias
User_Alias
User_Alias

83

MACHINE=COMMANDS
FULLTIMERS = millert, mikef, dowdy
PARTIMERS = ed, edd, eddy
OLDTIMERS = michael, jackson

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

SUDO

Edit /etc/sudoers file


Defining Run as Alias
Runas_Alias ALIAS_NAME = user1, user2
Examples:

Runas_Alias OP = operator
Runas_Alias DB = oradb, sysbase

84

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

SUDO
Edit /etc/sudoers file
Defining Host Alias
Host_Alias ALIAS_NAME = host1, host2
Examples:
Host_Alias SPARC = sun10, sparcstation10
Host_Alias LINUX = rhel6, rhel5, rhel4
Host_Alias
NFS = nfssrv1, nfssrv2

85

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

SUDO

Edit /etc/sudoers file


Defining Main Part
USER HOST = (RUNAS) COMMANDS
User_Alias Host_Alias = Cmnd_Alias NOPASSWD:/PASSWD:
Examples:
SYS ALL = SOFTWARE, LOCATE, MYCOMMAND
FULLTIMERS NFS = (OP) /bin/vi

86

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

SUDO

Example /etc/sudoers file


s udoers .txt

87

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Part 7
File Permissions
and Access

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


Access to files is dependent on a users identification
and the permissions associated with a file.
Types of Access
Read
files:
contents can be examined
directories: contents can be examined
Write
files:
contents can be changed
directories: contents can be changed
Execute
files:
files can be used as a command
directories: can become current working
directory

89

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access

90

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


chmod
touch
umask
chown
chgrp
su
newgrp

91

Change the file access


Update timestamp on file or create a new file
Change default file access
Change the owner of a file
Change the group of a file
Switch your user identifier
Switch your group identifier

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


chmod Change Permission of a file
Syntax:
chmod mode_list file
(s)

Change permissions of the file

Values
r
w
x

Read permission
Write permission
Execute permission

read 4
write 2
execute 1

Example:
chmod 777 f1

92

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


Symbolic
Method:

Set 1

Set 2

Set 3

u = user

+ = add

r =read

g = group

- = remove

w = write

o = others

= = set

x = execute

a = all

93

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access

Octal Method:
rwxrwxrwx = complete file permission
rwx||rwx||rwx
3 sets of rwx:
Set 1 is the permission for user owner
Set 2 is the permission for the group owner
Set 3 is the permission for others
94

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access

Octal Method:
Octal values:
R=4

w=2

x=1

If a file has a permission of rwxr-xr-x, the octal value


of the permission is ________.

95

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


Update timestamp on file or create a new file
Syntax:
touch [-amc] file
Example:
touch newfile
-a Change the access time to time
-m Change the modify time to time
-c If the file does not exist, do not create it
Note: touch command allows you to create a new, empty file. If
the file already exists, it will update the timestamp on the
file

96

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


umask - Permission Mask
Syntax:
umask [-S] [mode]
Example:
umask S
umask 072
Note: the mask that you designate will only be active in
your session, once you log out, it will revert back to the
default mask

97

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


chown Change File Ownership
Syntax:
chown owner [:group] filename
Example:
chown user2 /tmp/user2/f1
Note: Only the owner of a file (or root) can change the
ownership of the file

98

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


chgrp
Syntax:
chgrp newgroup filename
Example:
chgrp sys testfile
Note: Only the owner of a file (or root) can change the group
identifier associated of the file

99

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


chg Creating a shareable directoryrp
Syntax:
chmod g+rws testdir
Example:
chgrp groupshare testdir
Note: All users with the groupshare will be able to
write/change files within the testdir directory

100 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


su Switch User ID
Syntax:
su [username]
Example:
su ai9378

101 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

File Permissions and Access


1. Change the file permission of myfile to make it rw-r-xr-2. Update the timestamp of testfile to the current time.
3. Change your permission masking in a way that when you
execute umask S, the result will be u=rwx,g=r,o=r

102 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Part 7
ACL

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

ACL
OVERVIEW
- Why ACLs
- Types of ACL entries
- Enable ACL
- Viewing ACLs
- Applying ACLs

104 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

ACL
Why ACLs
- File owner controls permission
- Want to give specific user or group ability to
access to files and directories

105 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

ACL
Types of ACL Entries
Entry type
Owner
Named user
Owning group
Named group
Mask
Others

Text form
user::rwx
user:name:rwx
group::rwx
group:name:rwx
mask::rwx
other::rwx

106 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

ACL
Enable acl on filesystem
Set acl on filesystem
mount o acl

/dev/<device> /<mountpoint>

For persistent configurations(survive a reboot)


vi /etc/fstab
/dev/<device>

/<mountpoint> ext4 acl 1

1
107 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

ACL

View acl status - getfacl


- User utility to examine the ACL on a particular file
- Examines a files inode to detemine what
permissions are set
getfacl <file> / <directory>
# getfacl 123.txt
# file: 123.txt
# owner: root
# group: root
user::rwgroup::r-other::r-108 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

ACL
Set ACL on file / directory - setfacl
- User command utility to set, modify, or delete ACLs
on a file
- Can be ran by file owner or anyone given permission
to modify permissions
# setfacl m u:root:rwx file
Where:
-m
- modify
u
type of acl(user)
root name of the user
rwx type of permission(read only,write and
execute)
109 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

ACL

Examples:
setfacl
setfacl
setfacl
setfacl

s
m
u
d

u:alice:+rx:i myFile
o::drwx myFile
myFile
u:alice myFile

110 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Part 8
Linux Networking

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Ping

Uses the ICMP protocols mandatory


ECHO_REQUEST datagram to elicit
an ICMP ECHO_RESPONSE from a
host or gateway.
#ping <IP>
or
#ping <FQDN>
112 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Traceroute

Tracks the route packets take


across an IP network on their way
to a given host. It utilizes the IP
protocols time to live (TTL) field
and attempts to elicit an ICMP
TIME_EXEEDED reponses from each
gateway along the path to the host
#traceroute <FQDN>
#traceroute <IP>

113 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Ifconfig

Is used to configure the kernelresident network interfaces. It is


used at boot time to set up the
interface as necessary. If no
arguments are given, ifconfig
displays the status of the currently
active interfaces. If a single
interface argument is given, it
displays the status of the given
interface only.

114 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Ifconfig

# ifconfig
check the property of a single
network interface.
#ifconfig eth0
assign an ip on the fly
# ifconfig <IP> <netmask>
<device>

115 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Route

Manipulate the kernels IP routing


table. Its primary use is to set up
static routes to specific hosts or
networks via an interface after it
has been configured with ifconfig

116 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Route

Adds a route to the network


192.56.76.x via eth0
# route add net 192.56.76.0
netmask 255.255.255.0 dev eth0
check the currently routing table
#route -n
117 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Netstat

Print network connections, routing


tables, interface statistics,
masquerade connections and
multicast membership
display all tcp connections with its
associated program
#netstat -tap
118 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Ethtool

Query or control network driver and


hardware settings.
Check the interface property.
# ethtool <deviceName>

119 Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

Thank you

Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

You might also like