45
LINUX INTRODUCTION Linux partitions - / = root partition (holds all OS database) - /boot = holds booting files - swap = for support RAM Two environment of desktop GNOME DESKTOP ENVIRONMENT KDE DESKTOP ENVIRONMENT UNIT 2. Some basic commands used in terminal #passwd root : to change the root password #whoami : to know who is logged in #pwd : to show where the user is (the current directory) #ls : to see the content under the current location #ls / :to see the content under the root #cd /home : go into home directory #hostname : to know the computer name #reboot : restart the PC #init 6 : restart the PC #passwd username : change the password of any user

Linux + Session 17-05-11

Embed Size (px)

Citation preview

Page 1: Linux + Session 17-05-11

LINUX INTRODUCTION

Linux partitions

- / = root partition (holds all OS database)- /boot = holds booting files- swap = for support RAM

Two environment of desktop

GNOME DESKTOP ENVIRONMENTKDE DESKTOP ENVIRONMENT

UNIT 2.

Some basic commands used in terminal

#passwd root : to change the root password

#whoami : to know who is logged in

#pwd : to show where the user is (the current directory)

#ls : to see the content under the current location

#ls / :to see the content under the root

#cd /home : go into home directory

#hostname : to know the computer name

#reboot : restart the PC

#init 6 : restart the PC

#passwd username : change the password of any user

#mkdir : to make a directory

#touch : create blank file

#vi : to edit old file or create new file

Page 2: Linux + Session 17-05-11

#cat : to check contents of file

#clear : to clear the terminal window

#exit : to go out

#history : to see the list of the command you run previously

#init 0 : to shut down the system

#hostname (pc1) : to change your system’s name to (pc1) *applicable for the current session

HOW TO CHANGE THE HOST NAME PERMENANTETLY

#vi /etc/sysconfig/network (edit hostname)

Inside the file change the host name by press “I” then after changing the hostname put “ : ”; write “wq” : this will save changes and exit the file the goes back to the terminal

#vi Desktop/filename : to create a file on the desktop;follow the same steps in saving

#wq : saving the changes on a file

Other commands

#cal : calendar

#cal 2011 : calendar for the whole 2011

#date : current date

#ls --help same as #man ls

#man (any command) : to see help for any command

#!(number of the command) : run previous command with its number

If you write the whole command and you want to edit it you can use

Ctrl – a : to go back to the beginning of the lineCtrl – e : to go to the end of the line

#mkdir /mike/{d1,d2,d3,d4,…} : way of creating many files under (mike) directory

Page 3: Linux + Session 17-05-11

#cat filename | less same as #less filename : to see the contents of the file line by line

#cat filename1 > filename2 : copying the contents of file1 to new file2

#cat > filename…type something….Ctrl-z : the new file is created

#touch Desktop/filename : to create a blank file on the desktop

#|| : shows the recent command

&& : allow to run several commands at the same time

#tee : add text to an existing file

INSTALLING IN TEXT MODE

Boot from CD Type : linux text

GOING BACK TO GRAPHIC MODE

CRTL – ALT – F7START XCHVT 7

GOING TO TEXT

CTRL – ALT – F1

File system hierarchy standard

/ = root directory

/bin = system commands and binaries

/boot = bootloader

/dev = devices files

/etc = computer specific configuration files

/home = user files

Page 4: Linux + Session 17-05-11

/lib = programming library like DLLs

/mnt = temp mounting points

Pushd and popd

Pushd = save directory reference

Popd = retrieve directory reference

Both make it easy

MANAGING DIRECTORIES

Rmdir = remove directory

Mv = to rename or move a directoryRm –p = removing a directory that is not empty

Mkdir mike linux = creates two directories “mike” and “linux”

Mkdir ‘mike linux’ = creates one directory called “mike linux”

-f = forcing copy,delete

-u = updating the target file when copying

#ln filename1 filename2 = creates a link between flename1 and filename2#ln –s = symbolic link

File information commands

#file = describe the type of file

#stat = gets the info of the file

#test = tests the file

Page 5: Linux + Session 17-05-11

Finding files

#find . –atime0 = shows the files that have been accessed in the last 24hours

#locate ls = used to locate where LS is located

#whereis ls = shows the location of ls giving the whole path

#whatis = shows what is ls

MOUNTING

#mkdir /tmpcdrom = making directory for mounting

#mount /dev/cdrom /tmpcdrom = mounting the cdrom to the tmpcdrom directory

#mount /dev/sdb1 /flash = mounting the flash under flash directory

#cp Desktop/filename /flash = copying from the desktop to flash

#rm /flash/filename = removing filename from flash

#unmount /dev/sdb1 = unmounting flash

USERS AND GROUP

Creating users

The PASSWD file stores the info about every users (/etc/passwd)

UID = user identification…the number starts from 500 (root UID starts from 0)

Bash shell is created

A group and GID with the sane user’s name is created

Password information is stored in /etc/shadow

Group information is stored in /etc/group

Note: user has default home directory under /home/username/ and for root is /root

#useradd user1 = creating user name user1 the same as #adduser user1

#passwd user1 = creating password for user1

Page 6: Linux + Session 17-05-11

#usermod [options] username = making changes to the user

#chfn [options] [username] = change the properties of a user(locking)

#finger username = allows you to see the user’s information (old command)

#groupadd [options] group_name = creating users groups

#passwd –d [user] = to delete the password

#usermod –G username = allows you to add user to the existing group

#tail -1 /etc/group = to show the last line of the group

#userdel [-r]username = delete a user

#groupdel = delete groups

File ownership

#newgrp =

#chown [user] specifed file = change owner of a specified file

#chgrp [name] specified file= change group owner of a specified file

#ls –l [particular file] prompots you the below format

Dir/file User permissions Group permissions Others permissionsD/ - R W X R - X R - X

Followed by : root root……first root meaning the owner or user the second root meaning the group plus the date it was created and the name of the file

Permissions are given in numbers

Read = 4

Write = 2

Execute = 1

Dir/file User permissions Group permissions Others permissions

Page 7: Linux + Session 17-05-11

D/ - R W X R - X R - X

If you want to give WRITE permission to the group you give 2(based on the above table)

#chmod [path to a particular file]= to give permissions

#chmod 754 [particular file or folder] = this means

we are giving the user RWX permission

we are giving the group RX permission

we are giving the others R permission

#chmod [u,g,o] +/- [r,w,x] [specified file] = used to add or remove permissions

#umask = defines default permissions and the default umask is 022

File folder666 777022 022644 755

If we change unmask it can make effect on default permissions

Dir = drwxr-xr-xFile = -rw-r—r—

UMASK is the substractive method of changing default permissions of files and folder

Special permissions

Dir/file User permissions Group permissions Others permissionsD/ - R W S R - S R - T

#chmod 0755 = the lead zero means there is no sticky bit you are giving

Page 8: Linux + Session 17-05-11

#chmod 6755 = giving special permission and sticky bit on the sixth column

#chmod [u,g,o]+[s,t] = to apply special permissions

MANAGING AND INSTALLING PACKAGES

Packages/applications are also called RPM(Red hat Package Manager)

RPM command is applied on RED HAT VERSIONS

All packages are inside the folder called SERVER(dir) found inside the O.S cd

#mount /dev/cdrom /mnt = mounting the cdrom to /mnt dir

#ls /mnt/server = listing the available packages inside the SERVER dir

#rpm –iv [package] = to installation a package and see the process going on

#rpm –q(i) [package] = to see if a specified package is installed

#rpm –e [package] = to uninstall a package

#apt-get install [package name]

#dpkg –i [package name]

#dpkg –l = listing the packages installed

#apt-cach show = listing installed packages===============================================================#apt-get remove [package name] = removing a specified packages

#dpkg –r [package name] = removing a package

Apt-get autoremove = removing without asking

EXTRACTING

#tar –zxvf [filename]= available options of uncompressing the files

Z = compress/uncompress

X =

V = listing processed files

Page 9: Linux + Session 17-05-11

F =

CREATING PARTITIONS

#fdisk –l = lists the existing partitions

#df = lists mounted existing partitions or disk

#fdisk /dev/sad = creating new partitions

N = for new partition

First scylendor press enter

Second +spaceM = give partition space

P = to see the partition list

W = write and exit

#partprobe = to activate new partition without restart

#mke2fs –j /dev/sd4 = format the partition

#mount /dev/sd4 /secret = mount partition under /secret

Note : if you want to mount a partition permanently we have to make an entry in

/etc/fstab file

#parted [options] device [command]

#

#vi /etc/fstab

/dev/sd5 /secret ext3 defaults 00:wq

Page 10: Linux + Session 17-05-11

REQUIREMENTS

Create two partitions

100MB mount it to /batch1/music (temporarily)200MB mount it /batch1/personal (permanently)

INCREASING SWAP PARTITION AFTER INSTALLATION

1 – create a partition with swap ID (82)2 – mount it permanently in /etc/fstab3 – partprobe 4 – mke2fs –j /dev/sda11 (formatting swap partition which was created) then partprobe and run mount –a

5- increasing swap

- mkswap /dev/sda11 (making swap) - verify is this swap partition mounted under /etc/fstab

Swapon –a (to activate)

Swapon –s (to see swap partition)

QUOTAS

1 – limits disk usage (blocks or inodes)2 – tied to file systems (set on per file system basis)3- can be configured for users and groups

TASK : enable soft limit 50MB and 100MB for rahi user on /home

Steps to enable quota support

Page 11: Linux + Session 17-05-11

1.enable quota support per file system in /etc/fstab a.defaults,usrquota,grpquota2.remount the file system(s) a.mount –o remount / (mount –o remount /home1) (restart pc) b.use ‘mount’ to confirm that ‘usrquota,grpquota’ support are enables c.quotacheck /home d.quotaon /home e.edquota –u rahimake entried accordingly requirement

f. requota –a or #quota username

NOTE : the block are measured in 1K increments. i.e 20000 blocks is roughly 20MB

RAID

FEATURES1.ability to increase availability and reliability of data

TASK1 Create a RAID-1 device (/dev/md0..n) a.fdisk/dev/sda – to create 2 usable raw partitions with raid extension.I created /dev/sda5 and /dev/sda6

Page 12: Linux + Session 17-05-11

b.partprobe /dev/sda5.6 – to force a kernel update of the partition layout of the disk : /dev/sda5 and /dev/sda6 c.mdam –c /dev/md0 –l 1 –n 2 /dev/sda5 /dev/sda6 d.cat/proc/mdsta : list active RAID (md) information#mdam –detail /dev/md0 (check detail)

e. mke2fs –j /dev/md0 –overlays a file system on the RAID devicef. mkdir/raid1g. mount/dev/md0 /raidh. update: /etc/fstab

NOTE: use ‘mdadm –query /dev/md0’ to get information about a raid device

PROCESSES

#ps –f = lists full details about the process in your current shell

#ps –ef = lists full details about the processes across all terminals including daemons

#ps –l = lists the ull details ,plus the process flag (associated with the permissions),process state.wait channel and more

Page 13: Linux + Session 17-05-11

KILLING PROCESSES

#sighup(1) = hang up

#siginit (2) = interrupts foreground proc

#sigquit (3) = quit and save to core

#sigterm (15) = default kill command

#sigkill (9) = absolute kill

#pgrep = finds matching processes to kill

#pkill = kills the process you name

#killall = kills all the process by the name you provide

Signal trapping

Some processes are immune to the soigterm command for killing

Use the sigkill for those

Killing parent and child processes

BACKUP AND RESTORE Compressind and decompressing files

Gzip – compress/decompress files

Gunzip – decompresses gzip files

Compressing by gzip

Page 14: Linux + Session 17-05-11

#gzip file1 > file1.gz = compresses file1 to file1.gz

#gzip –l file1.gz = details of compressed file

#gunzip filename = extract or decompress file

Bzip2

#bzip2 –c file1 > file1.bz2

#bzip2 –d 1million.txt.bz2 (decompress)

Use full ectracting things

#tar –xvf filename.tar

#tar –xzvf filename.tar.gz

#dd if=/dev/cdrom of=/soft/rhel.iso = making ISO file

Scheduling tasks

#at press enter and type the task to be performed at that particular time

CRONTAB FORMAT

* * * * * command >> destinationMin hour d.o.m month d.o.w

Page 15: Linux + Session 17-05-11

#crontab –e30 17 * * * init 0 >> /dev/tty1*/2 * * * * cal >> /dev/console*/1 * * * * ping 127.0.0.1 >> /dev/tty1*/1 * * * * /bin/echo hello >> /dev/tty1 :wq#service crond restart

#crontab –l = to check what you set#crontab –r = to delete scheduled jobs

MONITORING TOOLS

#mpstat = multiple processors#iostat = i/o for each disk#sar = system activity mon

#free = memory and swap space#top = CPU stats,memory,swap#uptime#vmstat = swap performance

NETWORKING

Class A 1.0.0.0 – 126.0.0.0Class B 128.0.0.0 – 191.255.0.0Class C 192.0.0.0 – 223.255.255.0Class D 224.0.0.0 – 239.0.0.0Class E 240.0.0.0 – 255.0.0.0

IPV6

Page 16: Linux + Session 17-05-11

128bit = 2 power 128 addressesHexadecimal notation with colonsNo need for classful addressing

PORTS

20/21 FTP25 SMTP53 DNS80 HTTP110 POP3443 SSL

#less etc/services = top check the port numbers

NETWORK CONFIGURATION

#ifconfig = checking the ip address

#ifconfig [device name] [ip address] netmask [] broadcast []= setup a new ip address

#setup > select network > follow the instruction and give the ip

#system-config-network = give the IP addres graphicaly

#service network restart

#chkconfig network on = to start the service permanently

#ifup eth0 (ifconfig eth0 up)= enable the NIC

#ifdown eth0 (ifconfig eth0 down)= disable the NIC

#route = to manage your routing table

#dhclient eth0 = requesting the ip address from the DHCP

#dhcpcd =

#dhp3-client =

#cat /etc/sysconfig/network-scripts/ifcfg-eth0 = to see the details about eth0

Page 17: Linux + Session 17-05-11

DHCP SERVER SERVICES

Dhcp3-server package

Dhcp daemon

Dhcp.leases database

INSTALLING THE DHCP SERVICES

#mount /dev/cdrom /mnt/ = to mount the cdrom to mnt directory #rpm –iv /mnt/server/dhchp-3.0.5.7.el5.i386.rpm

#cat /etc/dhcpd.conf = sample file for dhcp

#cp /usr/share/doc/dhcp*/dhcpd.conf.cample /etc/dhcpd.conf

#vi /etc/dhcpd.conf = edit the file

#service dhcpd restart

#chkconfig dhcpd on

SHARING FILES

#showmount –e = to see shared data on local pc

#showmount –e [ip address] = to see shared data on a specified computer

To share /rahi for all and /rdb only for rdb users

#vi /etc/exports

/rahi *(rw,sync)/rdb 192.168.0.0/255.255.255.0 (rw,sync)/rdb2 rdb.com(rw,sync):wq

#service nfs restart#chkconfig nfs on

Page 18: Linux + Session 17-05-11

How to access client side

#mount –t nfs 192.168.0.1:/rahi /jkl = mounting temporarily

Mounting permanently

#vi /etc/fstab192.168.0.1:/rahi /jkl auto defaults 0 0:wq

PRINTING

#lpr = print document#lpc = status of the of the printer#lpq = view print jobs#lprm = remove orint jobs from the queue

INTEROPERABILITY

Samba

we use SWAT service to configure it

to share /win dir with windows computers

#mount /dev/cdrom /mnt/ = mounting #rpm –iv /mnt/Server/xinetd -2.3.14-10.el5.i386.rpm = installing dependency#rpm –iv /mnt/Server/samba-3.0.25b.0.el5.4.i386.rpm = installing samba rpm#rpm –iv /mnt/Server/samba-swat-3.0.25b-0.el5.4.i386.rpm = install rpm

#vi /etc/samba/smb.conf (edit in last line)

[rdb windows dir] Comment = for rdb users only Path = /win Public = yes Browsable = yes Writable = yes:wq#service smb restart#chkconfig smb on

Page 19: Linux + Session 17-05-11

INSTALLING SAMBA

NOTE : ultimately,user must authenticate to the local linux file system

Task 1

Install SWAT

a.yum –y install samba* (or) samba-swat

configure /etc/samba/smb.conf and after run #testparm (to check file error)

#vi /etc/samba/smb.com

*(in last)*

[rahi data]Comment = for rahi onlyPath = /rahiValid users = user1,user2,user3,user4Read list = user1,user2Write list = user3,user4Hosts allow = 192.168.0.0/255.255.255.0

:wq#service smb restart also disable selinux & firewall#testparm (to check file entries)#chcon –t samba_share_t /rahi (enable samba share)#smbpasswd –a user100 (give password)#smbclient //192.168.0.1 /rahi –U user100 (ip of samba server & share name)

NOTE : on windows client access data that is shared by samba

Page 20: Linux + Session 17-05-11

INSTALLING SAMBA

#mount /dev/cdrom /mnt#cd /mnt/Server/#rpm –iv xinetd-2.3.14-10.el5.i386.rpm#rpm –iv perl-convert-ASN1-0.20-1.1.noarch.rpm#rpm –iv samba-3.0.25b-0.el5.4.i386.rpm#rpm –iv samba-swat-3.0.25b-0.el5.4.i386.rpm

Now configure samba file

#vi /etc/samba/smb.conf (edit in last)

[rahi data] Comment = for rahi only Path = /rahi Valid users = user1,user2 Read list = user2,user1 Write list = user1 Host allow = 192.168.0.0/255.255.255.0:wq

#service smb restart#chkconfig smb on#testparm (to check entried)#chcon –t samba_share_t /rahi ENABLE SHARE#smbpassword –a user1 set smb password for user

Access on windows

Page 21: Linux + Session 17-05-11

SECURITY

#lokkit = to see the firewall configuration interface

CREATING A WEB SERVER

Install httpd rpm with dependencies

#rpm –iv apr-1.2.7-11.i386.rpm#rpm –iv postgresql-libs-8.1.9-1.el5.i386.rpm#rpm –iv apr-util-1.2.7-6.i386.rpm#rpm –iv httpd-2.2.3-11.el5.i386.rpm

#cp Desktop/inde.html /var/www/html#ls /var/www/html/

#vi /etc/httpd/conf/httpd.conf (last line)

<Virtualhost 192.168.0.100:80> ServerAdmin [email protected] Documentroot /var/www/html ServerName localhost.localdomain Errorlog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common</virtualhost>:wq

#service httpd restart#chkconfig httpd on

Page 22: Linux + Session 17-05-11

HOW TO BREAK THE ROOT PASSWORD

- restart the machine- press allow keys when the starting redscreen appears on the screen- press “e” to edit the commands before booting- press “e”- press space- press “1” or “s”- press “b”- a shell comes then set the new password for root

[email protected]@kist.ac.rw

Page 23: Linux + Session 17-05-11

SSH

Secure Shell.SSH is more secure that telnet used to access device anywhere in network via text mode.SSH has port number 22.also it’s better,more secure and easy to use in network environement.

Note: rpm is used “openssh” which is default installed in linux.if it’s not installed we can install it manually.

#service sshd restart#chkconfig sshd on

How to access client side#ssh ip#ssh username@ip/name#ssh [email protected]

Page 24: Linux + Session 17-05-11

FTP

File Transfer Protocol is used to transfer files from one pc to another.it has the port number 20,21Note : it uses “vsftpd” daemon/services in linux.and default path of ftp is

“/var/ftp/pub” also default user is “anonymous” and password is also “anonymous”

How to enable ftp on pc1

#rpm –iv vsftpd-2.0.5-10.el5.i386.rpm#service vsftpd restart#chkconfig vsftpd on

Note1 : now put/paste some data in /var/ftp dir. It will be available on client side.Note2 : you can login on client via simple user and anonymous user,but root can login default

Basic commands on client side

#ftp ip (to access the ftp server)#mget filename (to access/download file from server)#mput filename (to upload files on server)#bye (to close.disconnect ftp session with ftp)#cd (to change dir)#ls (to see the contents)

Page 25: Linux + Session 17-05-11

TROUBLESHOOTING

Run levels

(0) shutdown(1) single user mode(3) text mode(5) graphic mode(6) restart

How to set run level

#vi /etc/inittab

Change the id :[number] : default: to the run level number you want#wq#init 6 to reboot your system

How to change the title of O.S and increasing the timing of the red screen

#vi /etc/grub.conf

Edit the timeout to the number you want (timing comes in seconds)Edit the line that comes after “title” to the new name you want of your O.S

Networking troubleshooting utilities

#ping#ifconfig/iwconfig#ifdown/ifup (disable/enable NIC)#route (to check the current route table in our pc)#traceroute (to trace the router)#ftp ip (connect via ftp)#telnet ip (connect via telnet)#ssh ip (connect via ssh)#netstat (check network status)

Page 26: Linux + Session 17-05-11

Configuration:

Configuration of disk usage quotas on Linux - Perform the following as root:

1. Edit file /etc/fstab to add qualifier "usrquota" or "grpquota" to the partition. The following file system mounting options can be specified in /etc/fstab: grpquota, noquota, quota and usrquota. (These options are also accepted by the mount command but ignored.) The filesystem when mounted will show up in the file /etc/mtab, the list of all currently mounted filesystems.)

o To enable user quota support on a file system, add "usrquota" to the fourth field containing the word "defaults".

.../dev/hda2 /home ext3 defaults,usrquota 1 1...

o Replace "usrquota" with "grpquota", should you need group quota support on a file system.

.../dev/hda2 /home ext3 defaults,grpquota 1 1...

o Need both user quota and group quota support on a file system?

.../dev/hda2 /home ext3 defaults,usrquota,grpquota 1 1...

o This enables user and group quotas support on the /home file system. 2. touch /partition/aquota.user

where the partition might be /home or some partition defined in /etc/fstab. then chmod 600 /partition/aquota.user

The file should be owned by root. Quotas may also be set for groups by using the file aquota.group

Quota file names:

o Quota Version 2 (Linux 2.4/2.6 kernel: Red Hat 7.1+/8/9,FC 1-3): aquota.user, aquota.group

o Quota Version 1 (Linux 2.2 kernel: Red Hat 6, 7.0): quota.user, quota.group

The files can be converted/upgraded using the convertquota command.

Page 27: Linux + Session 17-05-11

3. Re-boot or re-mount file partition with quotas. o Re-boot: shutdown -r now o Re-mount partition: mount -o remount /partition

After re-booting or re-mounting the file system, the partition will show up in the list of mounted filesystems as having quotas. Check /etc/mtab:

.../dev/hda5 / ext3 rw,usrquota 0 0...

4. quotacheck -vgum /partition orquotacheck -vguma

o For example (Linux kernel 2.4+: Red Hat 7.1+, Fedora): quotacheck -vguma

quotacheck: WARNING - Quotafile //aquota.user was probably truncated. ...quotacheck: Scanning /dev/hda5 [/] donequotacheck: Checked 9998 directories and 179487 files

o For example (Linux kernel 2.2: Red Hat 6/7.0): quotacheck -v /dev/hda6

System response:

Scanning /dev/hda6 [/home] done Checked 444 directories and 3136 files Using quotafile /home/quota.user

5. Quotacheck is used to scan a file system for disk usages, and updates the quota record file "quota.user/aquota.user" to the most recent state. It is recommended thet quotacheck be run at bootup (part of Redhat default installation)

6. Man page: quotacheck - scan a filesystem for disk usage, create, check and repair quota files

7. quotaon -av System Response: /dev/hda6: user quotas turned on

quotaon - enable disk quotas on a file system. quotaoff - turn off disk quotas for a file system.

Man page: quotaon - turn filesystem quotas on and off

Page 28: Linux + Session 17-05-11

8. edquota -u user_id Edit directly using vi editor commands. (See below for more info.) For example: edquota -u user1

o System Response (RH 7+):

Disk quotas for user user1 (uid 501): Filesystem blocks soft hard inodes soft hard /dev/hda5 1944 0 0 120 0 0

blocks: 1k blocks inodes: Number of entries in directory file soft: Max number of blocks/inodes user may have on partition

before warning is issued and grace persiod countdown begins. If set to "0" (zero) then no limit is enforced.

hard: Max number of blocks/inodes user may have on partition. If set to "0" (zero) then no limit is enforced.

o System Response (RH 6):

Quotas for user user1: /dev/sdb6: blocks in use: 56, limits (soft = 0, hard = 0) inodes in use: 50, limits (soft = 0, hard = 0)

Something failed if you get the response:

/dev/sdb6: blocks in use: 0, limits (soft = 0, hard = 0) inodes in use: 0, limits (soft = 0, hard = 0)

Edit limits:

Quotas for user user1: /dev/hda6: blocks in use: 992, limits (soft = 50000, hard = 55000) inodes in use: 71, limits (soft = 10000, hard = 11000)

9. If editing group quotas: edquota -g group_name 10. Man page: edquota - edit user quotas

11. List quotas: quota -u user_id

Page 29: Linux + Session 17-05-11

For example: quota -u user1 System response:

Disk quotas for user user1 (uid 501): Filesystem blocks quota limit grace files quota limit grace /dev/hda6 992 50000 55000 71 10000 11000

If this does not respond similar to the above, then restart the computer: shutdown -r now

Man page: quota - display disk usage and limits

Quota Reports: Report on all users over quota limits: quota -q Quota summary report: repquota -a

*** Report for user quotas on device /dev/hda5Block grace time: 7days; Inode grace time: 7days Block limits File limitsUser used soft hard grace used soft hard grace----------------------------------------------------------------------root -- 4335200 0 0 181502 0 0bin -- 15644 0 0 101 0 0...user1 -- 1944 0 0 120 0 0

No limits shown with this user as limits are set to 0.

Man page: repquota - summarize quotas for a filesystem.

Cron:Quotacheck should scan the file system via cronjob periodically (say, every week?). Add a script to the /etc/cron.weekly/ directory. File: /etc/cron.weekly/runQuotacheck

Linux Kernel 2.4: Red Hat 7.1 - Fedora Core 3:

#!/bin/bash/sbin/quotacheck -vguma

Linux Kernel 2.2: Red Hat 6/7.0:

#!/bin/bash

Page 30: Linux + Session 17-05-11

/sbin/quotacheck -v -a

(Remember to chmod +x /etc/cron.weekly/runQuotacheck)

Edquota Note:The "edquota" command puts you into a "vi" editing mode so knowledge of the "vi" editor is necessary. Another editor may be specified with the EDITOR environment variable. You are NOT editing the quota.user file directly. The /partition/quota.user or quota.group file is a binary file which you do not edit directly. The command edquota gives you an ascii interface with the text prepared for you. When you ":wq" to save the file from the vi session, it is converted to binary by the edquota command and stored in the quota.user file.

Assigning quota for a bunch of users with the same value. To rapidly set quotas for all users, on my system to the same value as user user1, I would first edit user user1's quota information by hand, then execute:

edquota -p user1 `awk -F: '$3 > 499 {print $1}' /etc/passwd`

This assumes that the user uid's start from 500 and increment upwards. "blocks in use" is the total number of blocks (in kilobytes) a user has comsumed on a partition. "inodes in use" is the total number of files a user has on a partition.

edquota options:

Option Description

-r-m

Edit quotas on remote server using RPC. Remote server must be configured with the daemon rpc.rquotad

-u Edit user quota

-g Edit group quota

-p user-id Duplicate the quotas based on existing prototype user

-F format-F vfsold-F vfsv0-F rpc-F xfs

Format:vfsold - version 1vfsv0 - version 2rpc - quotas over NFSxfs - quotas for XFS filesystem

-f /file-system

Perform on specified filesystem. Default is to apply on all filesystems with quotas

-t Edit the soft time limits for each filesystem.

-TEdit time for user/group when softlimit is enforced. Specify number and unit or "unset"

Page 31: Linux + Session 17-05-11

Soft Limit and Hard Limits:

Soft limit indicates the maximum amount of disk usage a quota user has on a partition. When combined with "grace period", it acts as the border line, which a quota user is issued warnings about his impending quota violation when passed. Hard limit works only when "grace period" is set. It specifies the absolute limit on the disk usage, which a quota user can't go beyond his "hard limit".

Grace Period:

"Grace Period" is configured with the command "edquota -t", "grace period" is a time limit before the "soft limit" is enforced for a file system with quota enabled. Time units of sec(onds), min(utes), hour(s), day(s), week(s), and month(s) can be used. This is what you'll see with the command "edquota -t":

System response:

Linux Kernel 2.4+: Red Hat 7.1+/Fedora:

Grace period before enforcing soft limits for users:Time units may be: days, hours, minutes, or seconds Filesystem Block grace period Inode grace period /dev/hda5 7days 7days

Linux Kernel 2.2: Red Hat 6/7.0:

Time units may be: days, hours, minutes, or seconds Grace period before enforcing soft limits for users: /dev/hda2: block grace period: 0 days, file grace period: 0 days

Change the 0 days part to any length of time you feel reasonable. A good choice might be 7 days (or 1 week).

Quota files: (non-XFS file systems)

The edquota command will create/edit the quota file at the root of the file system. (See /etc/mtab for the list of the currently mounted filesystems.)

Version 2: aquota.user, aquota.group Version 1: quota.user, quota.group

The Linux Kernel:The default Red Hat/Fedora Core Linux kernel is shipped quota ready. If you have streamlined your kernel by rebuilding it with fewer options, make sure it has been configured with quotas support. When using the tools xconfig or menuconfig be sure to reply y to: Quota support (CONFIG_QUOTA) [n] y

Page 32: Linux + Session 17-05-11

Fedora Core 3: grep CONFIG_QUOTA /usr/src/redhat/SOURCES/kernel-2.6.9-x86_64.config Response:

CONFIG_QUOTA=yCONFIG_QUOTACTL=y

The Redhat default init script /etc/rc.d/rc.sysinit will also contain a point in the script to run quotacheck:

Red Hat 6, 7.0:

if [ -x /sbin/quotacheck ]; then echo "Checking root filesystem quotas" /sbin/quotacheck -v -afi

And turn quota checking on:

if [ -x /usr/sbin/quotaon ] then echo "Turning on quota." /usr/sbin/quotaon -v -afi

Links/Information:

Also note that system limits may be set in the configuration file: /etc/security/limits.conf. Here file size limits may be set for core dumps and data files as well as resource limits such as max cpu time and number of processes.

More Quota Info:

http://www.freebsd.org/handbook/quotas.html

Exploits:

http://listweb.bilkent.edu.tr/linux/06/0653.html

Software Available From:

ftp://ftp.funet.fi/pub/Linux/PEOPLE/Linus/subsystems/quota/all.tar.gz

Linux man pages:

quota - display disk usage and limits

Page 33: Linux + Session 17-05-11

rquota - implement quotas on remote machines fstab - static information about the filesystems edquota - edit user quotas setquota - set disk quotas (Command line editor) quotacheck - scan a filesystem for disk usage, create, check and repair quota files quotaon - turn filesystem quotas on quotaoff - turn filesystem quotas off repquota - produce a summary of quota information for a file system convertquota - convert quota from old file format to new one. Convert quota.user

to aquota.user quotactl - manipulate disk quotas (C programmer interface) Question 1

A customer wants internal office information to be accessible by employees through a Web browser. Which of the following Linux services should be used?

A. SquidB. MySQLC. ApacheD. sendmail

Question 2

Which of the following should be done before installing Linux on a home computer?

A. Upgrade the computer's memory to at least 64 MBB. Create ext2 and swap partitions on the hard driveC. Verify the hardware on the Linux hardware compatibility listD. Defragment the drive using the computer's current operating system

Question 3

Which of the following packages is usually more important for a "workstation" installation than a "server" installation?

A. DNS ServerB. DHCP ServerC. Proxy ServerD. XFree86 Server

Page 34: Linux + Session 17-05-11

Question 4

A new employee having a problem with account login has the following entry in the /etc/passwd file: user1:*:51:501:John Doe:/home/user1:/bin/bash

What is wrong with this entry in the /etc/passwd file?

A. The UID is not valid.B. The account is locked.C. The UID and GID must match.D. Spaces are not permitted between the first and last name.

Question 5

After having worked for several months, a PC fails to boot and indicates that the HDD has bad sectors. Which is the first action to take?

A. Reboot the system to remove the message.B. Run the manufacturer's Diagnostic Utility.C. Replace the defective HDD and reload the system.D. Run Scandisk and Defrag to repair the damaged sectors.

Question 6

A customer wants to determine which TCP ports are in use on his Linux server. Which of the following commands should be used?

A. tftpB. lsportC. minicomD. netstat

Question 7

A Linux superuser is unable to delete a file. The user is also unable to change permission for the file. What is the problem?

Page 35: Linux + Session 17-05-11

A. The file is actually a hard link.B. The file has the immutable flag set.C. The file has been fragmented across directories.D. The superuser does not have permission to access the file.

Question 8

Which of the following commands can be used to save and resume editing the file in the vi editor?

A. :wB. :xC. :vD. :s!

Question 9

A system technician needs to determine which hardware modules are loaded on a particular Linux server. Which of the following commands will perform this task?

A. lsmodB. modulesC. insmod -listD. modprobe -list

Question 10

What is the first step in troubleshooting a system problem?

A. Collect informationB. Test a possible solutionC. Make a hypothesis about a solutionD. Try to modify the configuration files