Süsteemihaldus MTAT.08.021

System Administration

File system basics shell basics

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 1/23 Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 2/23 Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 3/23 Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 4/23 Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 5/23 Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 6/23 points User System Profiles Root

/home /boot

Boot loader files and kernel /dev/sda

sda1 sda2 sda3 sda4

SWAP partition

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 7/23 Mount Points

● Configured in /etc/

● ~$ /etc/fstab # /etc/fstab: static system information. # # /dev/sda1 swap swap sw 0 0 /dev/sda2 / ext4 errors=remount-ro 0 1 /dev/sda3 /home ext4 defaults 0 2 /dev/sda4 /boot ext2 defaults 0 0

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 8/23 File System

● Root directory “/” – / ● Current directory – ● Home directory “~” – cd ~ – cd ● Parent directory “..” – cd .. ● Sub-directory /home and /home/user

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 9/23 File parameters

● ● Owner Name

● ● Group – File, Directory ● Permission bits – Link, FIFO, Block ● Date Modified device ● Size ~$ -l vpn_manual.txt -rw------1 devel devel 4740 Feb 20 14:39 vpn_manual.txt ~$ ls -l drwxr-x--- 10 devel devel 4096 Feb 21 06:02 Downloads ~$ ls -l text.txt lrwxrwxrwx 1 devel devel 19 Feb 21 06:02 text.txt -> vpn_manual.txt

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 10/23 File Name in UNIX

● Case sensitive – Downloads and downloads are two different files ● Hidden files start with “.” (use ls -la) ● File name max length 255 bytes ● File path max length none ● Reserved characters: & ; | * ? ` " [ ]( ) $ < > { } % ! # @ \ ● Escaping reserved chars: \( \) \# \! \?

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 11/23 Permissions

● Three types of permissions: – r – read: file or directory read access – w – : changing file or directory: ● add or remove files from directory – x – execute: running application file or command, in case of directory: enter or list directory contents ● The permissions can be changed by file owner or by superuser (root)

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 12/23 Permissions

● -r------400 u+r ● --w------200 u+w Owner user (u) ● ---x------100 u+x ● ----r----- 040 g+r ● -----w---- 020 g+w Owner group (g) ● ------x--- 010 g+x ● ------r-- 004 o+r ● ------w- 002 o+w All others (o) - world ● ------x 001 o+x

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 13/23 Changing permissions

g-rwx,o-rwx f1.txt ● Symbol Meaning

● chmod go-rwx f1.txt ● u user

● chmod a-x f1.txt ● g group

● chmod u+rwx,g+rx f1.txt ● o other

● a all

● chmod 600 f1.tx ● r read 400+200 user rw ● w write (and delete) ● chmod 644 f1.txt 400+200+40+4 ● x execute (and access user rw, group r, other r directory)

● chmod 640 f1.txt ?? ● + add permission

● - take away permission

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 14/23 Sticky bit

● Introduced in Unix 5 in 1974

● Originally was meant for optimizing most often executed program – The program stayed in memory after finishing execution, hence was started faster next ● Today used for protecting files in common directories – If directory has sticky bit set the file in the directory can be only removed by an owner the file even if directory has 777 permissions – Example: /tmp directory – writable for all, removing the files of other users prohibited user@localhost:~$ chmod 1777 test1/ user@localhost:~$ ls ­l drwxrwxrwt 2 user user 4096 Sep 23 09:30 test1/ Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 15/23 Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 16/23 UNIX Shell Basics

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 17/23 Command-line interpreters

● shell ● Wiki: A command-line interface (CLI) is a means of interaction with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines). ● sh, ksh, csh, zsh, tcsh, bash ● bash is default shell In GNU/Linux

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 18/23 Bash - Bourne-again shell

● Objective as a free replacement for the Bourne shell (sh) /bin/sh – Default Unix shell of Unix Version 7 (1977) – Developed by Stephen Bourne Bell Labs – Was a replacement for the Thompson shell, whose executable file had the same name—sh ● R.Stallman and the Free Software Foundation (FSF) considered a free shell that could run existing sh scripts so strategic to a completely free system built from BSD and GNU – The bourne-again shell (bash) was then developed by Brian Fox – So In Debian GNU/Linux /bin/sh is directly linked to /bin/bash

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 19/23 Command line

● General form:

~$ command -options parameters

● Options alternate or specify the command behavior ● Parameters provide the input data by values, or by giving the path to the file. Parameter values may also alternate command behavior

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 20/23 Command line

● ~$ vpn_manual.txt Manual for SA13 Configuration on GNU/Linux Configuring the OpenVPN * in this manual "username" refers to your username in this course (in class 123) To configure your openvpn you need certificates generated in first practical session. 1. First you need to install openvpn package. Install version not newer than 2.2 as 2.3 has a bug. For that either use command # apt-get install openvpn ... ● ~$ head -n 1 vpn_manual.txt Manual for SA13 Configuration on GNU/Linux

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 21/23 Command Line

● Help option “-h” or “--help” – Gives brief description of command usage

● ~$ --help Usage: tail [OPTION]... [FILE]... Print the last 10 lines of each FILE to standard output. With than one FILE, precede each with a header giving the file name. With no FILE, or when FILE is ­, read standard input. Mandatory arguments to long options are mandatory for short options too. ­c, ­­bytes=K output the last K bytes; alternatively, use ­c +K to output bytes starting with the Kth of each file ….

Artjom Lind ([email protected]) 23.09.2013 https://courses.cs.ut.ee/2013/syshald 22/23