Linux – Under the Hood Manual Pages & Info Pages Distribution Differences ● Package Management ● Startup and Shutdown Pesky Permissions Common/Useful Tools and Services ● cron ● find ● rsync
Manual Pages & Info Pages Pretty much all linux commands have a manual page. ● You can access them with ● – man <command> At the bottom of a page you will also often see a See also section like so ● – SEE ALSO – Regular Manual Pages – awk(1), cmp(1), diff(1), find(1), gzip(1), perl(1), sed(1), sort(1), xargs(1), zgrep(1), read(2), pcre(3), pcresyntax(3), pcrepattern(3), terminfo(5), glob(7), regex(7). The numbers after each command refer to sections of the manual. For example if ● you wish to view the page about regex which is in section 7 (sometimes commands will have man pages for the same command in multiple sections) you can use – man 7 regex In addition to the manual pages there are also info pages for a lot of common ● commands. These can be accessed by using – info <command>
Distribution Differences – Package Managers Debian / Ubuntu ● – Uses DPKG (debian package) packages. – Uses the apt (Advanced Package Tool) repository system. CentOS/Redhat (and Fedora) ● – Uses the RPM (Redhat package manager) package manager. – CentOS & Redhat Use Yum (Yellowdog updater). – Fedora as of version 22 uses DNF (Dandified YUM) rather than yum – but the commands are in most cases identical to those for yum.
Distribution Differences – Package Managers Managers vs Packages ● – yum/dnf and apt both manage the finding of packages and downloading them. They are also responsible for finding any packages the program your installing may also depend on and installing it too. – rpm and dpkg are used to query and install/remove the actual packages. They are what extract the archives and actually put the files in place and run scripts. These can also be used to query packages to list what files they provide etc…. Equivalent Ubuntu/Debian and Redhat/CentOS/Fedora Package Manager Commands
Distribution Differences – System Services init.d vs systemd ● – init.d is a well known structure for scripts that start and stop services. Depending on the age of your distribution you may or may not be using init.d scripts. Whilst most (not all) distributions seem to be moving to systemd some resist. – The main script files are usually stored in /etc/init.d The scripts in this directory are called with a start or stop parameter which then does the needed work to stop and start any particular service
Distribution Differences – System Services init.d ● – initd has a concept of run levels for the system numbered 0 – 6 (usually) Run level 0 – Shutdown ● Run level 1 – Single User (recovery mode no services running) ● Run level 2 – Ubuntu Multi user without network / Redhat Not used (user-definable) ● Run level 3 – Full multi-user with network - text mode (no GUI/display manager) ● Run level 4 – Not used – user definable ● Run level 5 – Ubuntu - Run level 3 + display manager / Redhat - Full multi-user graphical ● mode (with an X-based login screen) Run level 6 – reboot ● – The initial run level of a system using init.d scripts is set by the file / etc/ inittab – The startup/shutdown order of scripts is defined by the directories / etc /rc.d/rc. [0-6] which contain symbolic links to the scripts in / etc /init.d
Distribution Differences – System Services systemd ● Uses the command systemctl to manage the starting and stopping of services. ● Unlike init.d scripts systemd does not need to start everything in a specific order as it pre- ● creates things like socket files so that the daemons can attach to them once they are started. Because of this systemd startup times are often extensively faster than those using init.d. Systemd tasks are organised as units. There are several types ● – Services (.service) – Mount points (.mount) – Devices (.device) – Sockets (.socket) – Timers (.timer) The units are put into a control group named after the service. The system allows for a high degree ● of parallelism. Units are defined in files, normally these are located in / usr/lib/systemd/system but you can also ● create them in / etc /systemd/system. Files created in the /etc directory will take prescience over the ones defined in /usr For small tweaks to a service there is a drop in directory structure which can be used to tweak ● settings.
Distribution Differences – System Services The following distrubibutions use systemd ● – The versions listed are the first version where systemd was default, all distributions require systemd except where noted. – CentOS 7.14.04 – Debian v8 (Can run without systemd) – Fedora v15+ (current is 28, was the first to provide systemd) – Mint v18 – RedHat v7 – SUSE v12 – Ubuntu 13.04 (Can run without systemd) Most distributions provide a copy of the init.d service command which translates ● init.d style commands into systemd ones.
Permissions Standard Unix Permissions File/Dir ● Properties – Type of file – Permissions (User, Group Other, ACL/Sec Context) – Hard Links – File Owner (Name looked up from their UID in / etc/passwd ) – File Group (Name looked up from their GID in / etc /group) – Timestamp (usually modified time) – Filename
Permissions The command stat shows you more detail about a [lug@dave ~]$ stat hello ● file including User id (Uid) and Group id (Gid) File: hello Size: 0 Blocks: 0 IO Block: 4096 regular empty file It also shows the permissions as a bit mask ● Device: fd02h/64770d Inode: 105 Links: 1 – 0664/-rw-rw-r-- Access: (0664/-rw-rw-r--) Uid: ( 1000/ lug) Gid: ( 1000/ lug) – The first number is a special mode bit Access: 2018-10-23 21:51:56.219635662 +0100 Modify: 2018-10-23 21:51:56.219635662 +0100 normally this is just 0 unless your using Change: 2018-10-23 21:51:56.219635662 +0100 sticky bits (which would be another talk!!) Birth: - – The 3 basic bits you really need to start with are: The 0644 is the same as the more visual indications of 4 – Read ● ● permissions in this case in order. 2 – Write ● – 0 – The object is a File 1 – Execute (Note: on a directory this says you are ● – 6 – User Permission – so 4 & 2 = 6 which = read and write allowed to list the contents of the directory) for the user For those wanting more understanding there is an ● – 4 – Group Permission – so 4 on its own = read for the info page which details all this group – info coreutils – 4 – Other Users Permission – so again 4 on its own = other users can read (or if a directory can list the – Select Changing file attributes → Then chmod directory contents
Permissions Changing the Group (only) Changing ownership ● ● – You can change the group of a file – You can change a files – chgrp dialout myscript owner using chown – This would allow members of the dialout – chown <user> group to have access to the file myscript with the appropriate permissions set on <file/directory the file for that group. – An example would be chown pi mydatafile Its important to make sure ● – You can also change the your files are owned by group at the same time by the right user before adding a : and then the setting the group name permissions !!! – chown pi:pi mydatafile
Permissions To change a files permissions you can use ● Here are most of the permissions you can ● the chmod command. adjust – chmod can use both the numeric and rwx – Read (r) versions of permissions. I suggest you – Write (w) start with the rwx method on and read up on the other ! – Execute (or in the case of – In its basic form you can tell chmod to directories allow the change permissions for a file for the user,group,other to list the following contents of the directory) (x) User (u) These are demonstrated on the next slide. ● ● Group (g) Its important to make sure you know if ● Other (o) your adding a permission or removing it ● and more importantly setting it (=) as All (a) – Affects all 3 of the above ● setting the incorrect permission can be a – You tell it what to do to those entities problem. Sometimes its best to add the + Add the following permissions ● permission rather than set, this will - Remove the following permissions ● then retain the permissions it has and = Set to these permissions just add the additional option for read ● rather than overwriting to just read!
Permissions A simple example: to perform the Set all to add read and execute ● ● following actions on the file myscript – chmod a+rx myscript – give a user the read permission chmod u+r myscript ● Set all to only have read and execute – Remove the read permission ● chmod u-r myscript ● – chmod a=rx myscript – Give the group read permission chmod g+r myscript ● – Remove the group read permission Finally a slightly more complex example. ● chmod g-r myscript ● Set the user to read + execute, the – The same format goes for the other users just replace the u or g with group to read and write and remove read, o write and execute from other You can also do combinations ● – chmod u+rx,g=rx,o-rwx myscript – chmod ug+rwx myscript This sets the user and group read, ● write and execute permissions – chmod ug+rwx myscript This Adds the user and goup read, ● write and execute permissions
Recommend
More recommend