sections in this module City College of San Francisco - CS260A
Linux System Administration

Module: ssh and VNC
module list

Essential Privileged Commands

In this section we will cover simplified versions of skills that are fully explained later. This course has an unfortunate number of chicken-and-egg issues - it is difficult to explain virtual machines, for example, without understanding the startup and shutdown process, subsystems, and filesystems. Similarly, you may have to install a package or kill a process. In this section we will introduce some of those topics in a simplified manner to get us started. These topics will be explained fully later.

Filesystems

As you probably know, most Linux systems contain multiple filesystems (partitions). Each of these is attached or glued into the single [logical] filesystem at a directory. This process of gluing a partition to a directory is called mounting the partition at the directory. The directory the filesystem is mounted at is the mount point. When the filesystem is laid out, the root partition is mounted first, then the other partitions are mounted and attached to it.

You can review which filesystems are mounted by looking at the output of the mount command. As of SL7, this has gotten much more complicated, as all sorts of pseudo-filesystems are mounted. You can filter out many of the pseudo-filesystems by grepping the output for /dev

[gboyd@nelson ~]$ mount | grep /dev
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=6003660k,nr_inodes=1500915,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
/dev/sda2 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
/dev/sda1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=winnt,errors=remount-ro)
/dev/sda5 on /var type xfs (rw,nosuid,nodev,relatime,seclabel,attr2,inode64,noquota)
/dev/sda4 on /tmp type xfs (rw,nosuid,nodev,relatime,seclabel,attr2,inode64,noquota)
/dev/sda7 on /virt type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sda6 on /spare type xfs (rw,nosuid,nodev,noexec,relatime,seclabel,attr2,inode64,noquota)
[gboyd@nelson ~]$

In this output, all the "real" filesystems are hard partitions. These are indicated by a line like

/dev/sda2 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

which indicates that the second partition on disk sda is mounted at the directory / (the root of the filesystem). The type is xfs which is a linux filesystem. Options include that it is read-write, uses 64-bit inodes, the new format for extended attributes, and the restrictive rules on updating the access time.

A real filesystem may also be a logical volume. It is indicated somewhat differently in the output of mount, like this:

/dev/mapper/rhel-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

For our purposes now, logical volumes and physical filesystems are manipulated the same. In the line above, the logical volume "device" (/dev/mapper/rhel-home) can be used as a hard partition device in the mount command with exactly the same syntax.

Other lines in the output of mount indicate pseudo-filesystems. These are catalogs of information that are accesses as if they are filesystems, but they are not. For our purposes with mount, we are only concerned with the real filesystems.

The list of filesystems to be mounted at boot, and where they come from, is stored in the filesystem table - /etc/fstab. You can umount and mount these filesystems if needed. So long as the filesystem is specified in /etc/fstab, all you need to give is either the mount point or the device. Thus, in the list above, you could unmount the filesystem that is mounted at /spare either by

umount /spare

or

umount /dev/sda6

Similarly, you could remount it using the same commands - just change umount to mount.

A more reliable list of the filesystems currently mounted can be viewed in the /proc/mounts file. (/proc is one of those pseudo-filesystems. It is really a request to the kernel to give you some information. The information is displayed as if it was a file!) The mount command simply outputs the current copy of the mtab file, which is supposed to reflect the last filesystem update, assuming the mtab file was successfully updated (which is not the case if the root filesystem is mounted read-only). The /proc/mounts file is a real-time list of mounted filesystems from the kernel's internal tables.

Adding and deleting users and groups

You can very simply create a user or group just by using

useradd username

or

groupadd groupname

The default parameters on your system for the user are filled in (shell, home directory, uid, etc.) When a new user is created like this a new group is also created just for the new user. The new user is the only member of the newly-created group and the group is named the same as the user.

After you create the user, the account cannot be accessed. This is because you haven't created a password for the user. Just use passwd username.

A group or user can be deleted using userdel/groupdel. If you want to remove the user's home directory you must add the option -r to the userdel command. Thus, the sequence

useradd newuser

adds the new user newuser (and creates a new group named newuser for that user) and the sequence

userdel -r newuser

groupdel newuser

deletes the newuser, their home directory, and their group.

Services

As we will learn later, system applications (and their support files) that provide a system function are called services in RH7 and services or subsystems in RH6.5. Services can be manipulated easily - it simply requires

In RH7, services are manipulated using systemctl verb service-name
in RH6.5, services are manipulated using service service-name verb  (yes, the arguments are reversed - it is maddening). The RH6.5 version will normally work in RH7 - it is emulated.

Examples

if you change some network parameters by altering a file instead of using Network Manager, or if you just want to reinitialize the network at the command-line use

systemctl restart network  or  service network restart

if you added a package for a new subsytem foo and want to start it

systemctl start foo  or   service foo start

These commands only affect the status of a service now. When the system is restarted, the service status will return to whatever its default configuration is. If you want to alter the default status (enabled (on) or disabled (off)) of a service when the system starts you must use

systemctl enable service-name  (RH7)

chkconfig service-name on  (RH6.5)

For example,

systemctl enable foo

chkconfig foo on

This will ensure that the service foo is started when the system boots. (Again, this is not the entire story - we will cover services fully later in both RH6.5 and RH7)

Starting and stopping the window manager

Again, as we will learn later, "subsystems" (RH6.5 - also called services) are transitioning to a more modern control mechanism. This was begun in RH6.5. There the new control mechanism was upstart. upstart was never fully embrace by Redhat, and most of the subsystems were left in-place, and just operated under upstart. In RH7, the new control mechanism is systemd (whose interface is systemctl), which is a big change. Even though most configuration files were ported from subsystems to systemd, a compatibility mode was introduced so that the service command tries to translate the most commonly-used service commands to the equivalent systemd commands.

There is one function, however, that was removed entirely from a subsystem in both RH6.5 and RH7. That is the control of the window manager (the X server):

To restart the X server on 6.5 use the upstart command

initctl restart prefdm

To restart the X server on RH7 use the systemctl command

systemctl restart display-manager

Killing a process

The simplest way to kill a process is to discover its process id and, using it, to invoke the kill command:

kill pid

If the process doesnt exit after a few seconds you can force kill the process using

kill -9 pid

Shutting down a system

The easiest way to shut down or reboot a system is to use the command poweroff or reboot. When you are using virtual machines, please ensure that the window in which you issue this command is the virtual machine's window, and not the host's window.

Package management

Using yum and rpm can be complicated, and we will go over it in more detail at the end of the semester. For now, we simply need commands to determine what package contains a file we need, then, once we've figured out the package we need, to install it. First, simply installing a package is very easy, assuming you know the name of the package. If so, use

yum install package-name

yum will add any packages to the installation that package-name depends on. You will be asked for verification before the installation proceeds.

you can also update packages using yum update package-name

To find out what package you need, assuming you know the name of a program you want, use yum whatprovides. Suppose you need the program gconf-editor. As long as you know the name of the program file you dont need to know where it is installed. Just use

yum whatprovides */gconf-editor

yum will output a list of packages that provide that file. Choose the best match and do the installation!



Prev This page was made entirely with free software on linux:  
the Mozilla Project, Kompozer,
and Openoffice.org    
Next

Copyright 2015 Greg Boyd - All Rights Reserved.