Wecksten, Mattias 2008
Administration of Operating Systems
DO2003
Mounting the file structure Devices
Wecksten, Mattias 2008
Partitioning
Files on the Hard Drive
• Partition = Binder with index
• Write file = Insert document
• Remove file=
Erase from index
• Format = Replace index
Wecksten, Mattias 2008
Disk = container of partitions
HDA
HDA1 HDA2 HDA3
Linux MS-dos
Wecksten, Mattias 2008
Partitions
HDA
HDA1 HDA2 HDA3
/home /boot
Mount partitions
• HDD A
• Partition 1, 3 Gig
• Partition 2, 3 Gig
• Partition 3, 15 Gig
• Partition 4, 500 Meg
• CD/DVD
• Floppy
/ /etc
/usr
/home
/media
/mnt/floppy /mnt/cdrom
/boot
Wecksten, Mattias 2008
mount
• Mount makes it possible to mound devices into the file structure.
mount /dev/hda2 /home mount -t ntfs /dev/hda1 /extra mount -t auto /dev/fd0 /mnt/floppy
mount -t nfs server:/all_home /home mount –t smbfs //ip/path /mountpoint
Wecksten, Mattias 2008
Detailed structuring
Partitions
Minimal setup – Partitions in Linux
• Size
• Required size
• Type
• Filsystem to use
• EXT3
• SWAP
• Mount point
• Where to mount
• /home
Wecksten, Mattias 2008
Partition example
• Swap
• ~1x volatile memory (desktop).
• 1x - for servers.
• /boot
• Kernels + initrd (small).
• Partition = read only possible
• /usr
• Shared, program installations (large).
• /home
• All user files (large).
• Partition = portable
Wecksten, Mattias 2008
File system commands
• df
• List partitions
• mount
• umount
• showmount
• /etc/fstab
• /etc/mtab
Permissions
Users & groups Permissions Ownership
Wecksten, Mattias 2008
Users and Groups
Wecksten, Mattias 2008
Users
• Add a user
• Edit /etc/passwd
•Create folders...
• Use adduser
•Use the skel-folder
•Use third party software.
• Deactivate vs. remove users.
/etc/passwd
Name:Password:UserID:PrincipleGroup:Gecos:HomeDirectory:Shell
smith:*:100:100:8A-4(office):/home/smith:/usr/bin/sh guest:*:200:0::/home/guest:/usr/bin/sh
Wecksten, Mattias 2008
adduser
lygos% sudo adduser kalle Password:
Adding user `kalle'…
Adding new group `kalle' (1004).
Adding new user `kalle' (1004) with group `kalle'.
Creating home directory `/home/kalle'.
Copying files from `/etc/skel' Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully Changing the user information for kalle Enter the new value, or press ENTER for the default Full Name []: Kalle Karlsson
Room Number []: D687 Work Phone []: +46-35-123456 Home Phone []: +46-35-234567 Other []:
Is the information correct? [y/N] y
Wecksten, Mattias 2008
Edit groups
• groupadd
• newgrp
• /etc/group
Change password
lygos% passwd kalle
passwd: Changing password for kalle Enter login(NIS) password: ******
New password: ******
Re-enter new password: ******
NIS passwd/attributes changed on the server.
lygos% sudo passwd kalle New password: ******
Re-enter new password: ******
NIS passwd/attributes changed on the server.
lygos% _
Wecksten, Mattias 2008
useradd – skeleton folder
% ls -A /etc/skel
.bash_profile .bashrc .maildir .screenrc .tcsh.config
% useradd –k adam
% _
• Copies the skeleton to the empty user folder.
Wecksten, Mattias 2008
How to handle MANY users?
How to handle MANY users?
#167
#RNDTXT -> hgR5@%lkoRT5
#CRYPT -> af38$12rsqqK
#167 af3...
Wecksten, Mattias 2008
How to handle MANY users?
#167
#167 af3...
#uid
#login
#167 af3...
user
admin
Wecksten, Mattias 2008
How to handle MANY users?
hgR
#167
#uid
#login
#167 af3...
CRYPT
Linux File Permissions
Wecksten, Mattias 2008
Linux file permissions
drwxr-x--- 2 mayank freeos 4096 Dec 28 04:09 tmp -rw-r--r-- 1 mayank freeos 969 Dec 21 02:32 foo -rwxr-xr-x 1 mayank freeos 345 Sep 1 04:12 scr
•
owner-group-all
•
r – read. Folders = list. Files = read.
•
w – write. Folders = change content/remove/change name.
Files = write/remove/change name
•
x – execute. Fodlers = open. Files = execute.
Wecksten, Mattias 2008
Stickybit
• Prevent
• deleteion
• renaming
• chmod +t fp
setuid / setgid
• Files
• Inherit owners permissions
• Folders
• Inherit group
Wecksten, Mattias 2008
chmod
raynas.hh.se% chmod 755 testtext.txt raynas.hh.se% ls -la testtext.txt -rwxr-xr-x 1 weck 6 Nov 3 09:31 testtext.txt raynas.hh.se% chmod 700 testtext.txt raynas.hh.se% ls -la testtext.txt -rwx--- 1 weck 6 Nov 3 09:31 testtext.txt raynas.hh.se% _
Wecksten, Mattias 2008
chown
chown -vR owner filename chown owner:group filename
lygos% sudo mkdir /usr/local/pgsql lygos% sudo chown postgres /usr/local/pgsql lygos% sudo chown root:users gemensam
Installation
Software Updates
Wecksten, Mattias 2008
Install software (RedHat)
• rpm - single packets – rpm –qa – rpm –i <package>
– rpm –U <package>
• yum – packet manager
Wecksten, Mattias 2008
Install software (Debian)
dpkg–packet based
apt-get update - synchronize the databases
apt-get upgrade
apt-get install package
–
packet manager aptitude - better than apt-getBasic Process Handeling
Wecksten, Mattias 2008
Scheduling
RUN
READY WAIT
Wecksten, Mattias 2008
Schedule examples
Schedule examples (priority)
Wecksten, Mattias 2008
Processes i LINUX
lygos.hh.se% ps -la
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 8 O 0 23201 23173 0 50 20 ? 140 pts/6 0:00 ps 8 S 616 15644 15630 0 50 20 ? 1074 ? pts/2 0:05 dtsessio 8 S 616 15904 15643 0 45 20 ? 139 ? pts/2 0:00 sh 8 S 616 15905 15904 0 40 20 ? 1093 ? pts/2 0:08 dtfile 8 S 616 15909 15905 0 40 20 ? 1064 ? pts/2 0:00 dtfile 8 S 616 15630 15627 0 54 20 ? 318 ? pts/2 0:00 tcsh 8 S 616 18612 18611 0 40 20 ? 915 ? pts/2 0:00 dtpad 8 S 616 18611 15643 0 41 20 ? 139 ? pts/2 0:00 sh 8 S 616 15643 1 0 40 20 ? 688 ? pts/2 0:01 ttsessio lygos.hh.se% _
Wecksten, Mattias 2008
top
load averages: 0.00, 0.00, 0.01 23:06:43 48 processes: 47 sleeping, 1 on cpu
CPU states: 100% idle, 0.0% user, 0.0% kernel, 0.0% iowait, 0.0% swap Memory: 256M real, 119M free, 330M swap in use, 318M swap free
PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND 13492 weck 1 59 0 2808K 2464K sleep 0:00 0.23% tcsh 13488 root 1 60 0 6096K 2752K sleep 0:00 0.16% sshd 13498 weck 1 59 0 1960K 1248K cpu 0:00 0.14% top_5.9
1 root 1 59 0 1240K 184K sleep 10:59 0.02% init 13490 weck 1 59 0 6224K 2496K sleep 0:00 0.02% sshd 209 root 27 59 0 4712K 3096K sleep 22:06 0.00% nscd 184 root 15 59 0 3504K 1648K sleep 20:14 0.00% syslogd 145 root 1 59 0 2208K 1128K sleep 18:20 0.00% inetd 9029 nobody 1 59 0 3912K 2224K sleep 11:36 0.00% lmgrd 21697 root 1 59 0 3344K 1784K sleep 9:47 0.00% sshd
Process management
• If you start a program from the shell, the shell will wait for the program to exit before you can do anything more.
• To interrupt the program you press <ctrl><c>
• This usually exits the program back to the terminal.
• To suspend the program you press <ctrl><z>
• This puts the process resting in the background and you get back the terminal.
• To restart the program in the foreground again, give the command fg.
• To restart the program in the background, give the command bg.
Wecksten, Mattias 2008
Background processes
• Start a process as a background process.
lygos.hh.se% netscape &
[1] 23276 lygos.hh.se% _
Wecksten, Mattias 2008
Kill processes
• kill pid
lygos.hh.se% ls -R /* > /dev/null &
lygos.hh.se% ps PID TTY TIME CMD 23173 pts/6 0:00 ls 23170 pts/6 0:00 tcsh lygos% kill 23173
[1]Terminated ls -R /* > /dev/null lygos% _
Stop signals
ALRM 14 exit
HUP 1 exit
INT 2 exit (equal to ctrl-c)
KILL 9 exit (this signal can not be caught)
PIPE 13 exit
TERM 15 exit
ABRT 6 core
FPE 8 core
ILL 4 core
QUIT 3 core
SEGV 11 core
TRAP 5 core
lygos% kill -9 23173
[1]Terminated ls -R /* > /dev/null lygos% _
Wecksten, Mattias 2008
Filtering signals
• To avoid the hup signal you can start a program with nohup.
lygos.hh.se% nohup netscape &
[1] 23276
Sending output to nohup.out lygos.hh.se% _
Wecksten, Mattias 2008
Priority
• Lower
lygos% nice -5 netscape &
• Increase
lygos% sudo nice --5 netscape &
Control priority
lygos.hh.se% ps PID TTY TIME CMD 23173 pts/6 0:00 netscape 23170 pts/6 0:00 tcsh lygos% renice -5 23173 lygos% _