Homework & Review
description
Transcript of Homework & Review
![Page 1: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/1.jpg)
Homework & Review
• Please turn in homework and practicals• Review:
– Absolute Path– Relative Path– Linux Directory Structure– Shell look and feel
![Page 2: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/2.jpg)
Today
• Linux Folders• Permissions• Directories
![Page 3: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/3.jpg)
Hi Again Tom• I like Tom – it’s a great visualization of paths
![Page 4: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/4.jpg)
Important Directories
• /bin - commands• /dev - devices• /etc - system configuration• /home - user files• /opt - application directory• /root - root user’s home directory• /sbin - commands• /tmp - temporary files• /var - changing files• There are more, but we’re starting here
![Page 5: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/5.jpg)
Quick Aside Windows has .exe files for ‘executable’
How you differentiate programs from other files Linux doesn’t have this
You can only tell executables by the permissions What flag on the ls command would show
permissions?
Commands are “programs”
![Page 6: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/6.jpg)
Folders - /bin, /sbin and /dev /bin and /sbin – commands
/bin/ls /sbin/ip
/dev – devices /dev/hdd – IDE hard drives /dev/sda – SATA/SAS hard drives /dev/tty – userspace /dev/cciss – HP’s RAID /dev/dvd – DVD /dev/vg_it136centos65vm – Virtual HDD space
Run the df command to see
![Page 7: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/7.jpg)
Folders - /etc, /home, /opt /etc – configuration files
Configures applications on the system Both integrated and not /etc/sudoers, /etc/httpd/conf/httpd.conf /etc/named.conf, /etc/dhcpd.conf
/home – default user space /home/<username> Users will then create/manage their own files/directories
/opt – third party application space Anything you buy from someone that “runs on Linux”
should be here If it’s not that is a BIG red flag (usually)
![Page 8: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/8.jpg)
Folders - /root, /tmp, /var /root – home directory for the root user,
usually contains backups of configuration files or is a staging area for administrative tasks
/tmp – temporary space, some OS “lock” files, staging area for updates/installations
/var – files that will change through the course of normal system operation (mail, logs, some databases/web servers)
![Page 9: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/9.jpg)
Permissions Permissions in Linux are shown by the ls –l
command -l stands for ‘long list’ which includes the
permissions, owner, and group Linux permissions are shown in two ways
Octal and symbolic Each break permissions down into three groups
1) user/owner of the file 2) group set to use the file 3) everyone else
![Page 10: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/10.jpg)
Octal Three groups of numbers, each number runs
from 0 through 7 777, 733, 755 (three very common
permissions), 456, 523, 123, are other possibilities
So each numerical value has a defined level of access: 0 – no access for anybody 1 – execute permissions 2 – write permissions 4 – read permissions
![Page 11: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/11.jpg)
Oct-wait, what?!
1, 2, 4?! Yes, how’s your math? Every unique combination now stands for a
unique type of access If read was 3 (and not 4), then what would
happen if we wanted to make a file that was executable, and writeable?
![Page 12: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/12.jpg)
Octal Math Unique options are 3, 5, 6, and 7 from
1) execute 2) write 4) read
So, what do these unique options mean 3 = 5 = 6 = 7 =
![Page 13: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/13.jpg)
Octal Permissions (partial) So what does ‘read,’ ‘write,’ and ‘execute’ mean? File:
4) Read: You can read the contents (cat, vi but no saving)
2) Write: You can edit the file (vi, plus saving!) 3) Execute: If it’s a script, you can run it (./)
Directory: 4) Read: You can see what’s inside (ls) 2) Write: You can create new files (touch, vi + saving!) 1) Execute: You can move inside the directory (cd)
![Page 14: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/14.jpg)
Symbolic Permissions
Read, write, and execute are now letters Read: r Write: w Execute: x No permissions: - Now there are three spaces: ---
![Page 15: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/15.jpg)
Symbolic Permissions, cont’d Meaning stays the same: Files:
r - can cat the file, open in vi without saving w - can save in editor (vi) x - can run the script No permissions: -
Directories: r - can do an ls to see files inside w - can create new files (vi/touch) x - can move inside
![Page 16: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/16.jpg)
Groups of Groups
So we have three options (read, write, execute) These options combine into three groups User/owner – the primary user (owner) of the
file Group – the primary group the file is associated
with Others – everyone else not the primary user
(owner) or group Don’t get ‘owner’ and ‘others’ confused!
![Page 17: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/17.jpg)
Groups of Groups, again
Each group gets a full set of permissions Octal
000 (no permissions to anyone) 777 (full permissions to everyone)
Symbolic --------- (no permissions to anyone) rwxrwxrwx (full permissions to everyone)
Or some combination
![Page 18: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/18.jpg)
Groups of Groups, 3
Each set of permissions stands for a different group
Octal 7 7 7 Owner Group Others
Symbolic rwx rwx rwx Owner Group Others
![Page 19: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/19.jpg)
Real Example
[student@it136centos58vm ~]$ ls -l
total 20
-rw-rw-r– 1 student student 29 Apr 17 16:53 err.out
-rwxrwxr-x1 student student 29 Apr 17 16:53 script.sh
-rw-rw-r– 1 student student 29 Apr 17 16:53 teams2.txt
-rw-rw-r– 1 student student 29 Apr 17 16:53 teams.txt
permissions owner group filename
![Page 20: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/20.jpg)
Manipulation Commands mkdir <arg> – make new directory at (and
named) <arg> - ~/backups or /tmp/test cd <arg> – change directory into ‘arg’ (path) ls -l <arg> – list file permissions at ‘arg’ (path) chmod <arg1> <arg2> - change the
permissions to ‘arg1’ (new permissions) on ‘arg2’ (file/path), explained next slide
chmod is awesome, works on directories or files
![Page 21: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/21.jpg)
chmod
chmod <permissions> /path/to/anything chmod <permissions> /etc/passwd chmod <permissions> ~/myscript.sh <permissions> Can be octal or symbolic Otcal: chmod 755 ~/myscript.sh chmod 700 ~
![Page 22: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/22.jpg)
chmod, symbolic Symbolically, we can update one specific group
(user_owner, group, others) chmod g+rwx file - give rwx to the group chmod o+rwx file - give rwx to ‘others’ chmod u+rwx file - give rwx to the user/owner chmod a+rwx file - give rwx to everyone chmod o-r file - remove read permissions from
‘others’ chmod u-x file - remove execute permissions
from user/owner
![Page 23: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/23.jpg)
Your Turn – Interpret the Following Octal: User full, group read, nothing for others
755
Symbolic: User read and write, group write, others read
r-xrw---x
![Page 24: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/24.jpg)
Necessary File Permissions• To read a file (cat, less, grep, etc…)• As owner -r--------; group ----r-----; other_users -------r--• To write to a file (vi, nano, emacs, etc…)• As owner -rw-------; group ----rw----; users -------rw-• You need to be able to read (see the contents of) the file you
want to write to • You can’t write in a book unless you can open the book• To run a script (./script.sh)• As owner -r-x------; group ----r-x---; users -------r-x• Again, you need to be able to see the contents of the script to
know what actions the script is telling you to do• These are all file-based (not directory)
![Page 25: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/25.jpg)
Necessary Directory Permissions• To list the contents of a directory (ls backups)• Owner: -r--------; group: ----r-----; users: -------r--• To move into a directory (cd backups)• Owner: ---x------; group: ------x---; users: ---------x• Note that execute-only will not allow the user to do an ls• Create or modify files inside a directory (touch/echo/vi)• Owner: --wx------; group: ------wx---; users: --------wx• Note - you will still not be able to do an ls as you do not have
‘read’ permissions• Run scripts inside a directory (./script.sh)• Owner: --wx------; group: ------wx---; users: --------wx• Note - again, if something inside the script requires read
permissions, it will not work, but the script will run
![Page 26: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/26.jpg)
Questions on Permissions?
Symbolic or octal Three groups of three Read, Write, Execute, None User/owner, Group, Others chmod
![Page 27: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/27.jpg)
Switch User su <username>
Will switch to the account named <username> su
Will switch to the ‘root’ or admin account Root has all privileges Used for adding users,
patching/updating/installing, reading log files, troubleshooting and other administrative tasks
![Page 28: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/28.jpg)
Corporate Environments As an admin you’ll get several passwords 1) Your own (as a “power user”) 2) An account that can access all devices (if needed) 3) Administrator/root password #3 is what is known as the ‘keys to the kingdom’ –
Windows group doesn’t share with Linux group, which doesn’t share with network group
Keep the root pw extremely confidential Is usually something clever like we have so they can
reference it out loud without others knowing exactly what it is
![Page 29: Homework & Review](https://reader034.fdocuments.us/reader034/viewer/2022051821/5681660e550346895dd94fec/html5/thumbnails/29.jpg)
Own Study Folders review
Sobell Ch 4 – The Filesystem (81-89) Permissions