Lesson 2: Single System Fundamentals

Or, how to be a power user.

Housekeeping

_images/virtualbox.png

10 minutes to make sure everyone's Virtualbox instances are up and running

Your opinions:

Today's Topics

What are users?

$ whoami    # your username
$ who       # who is logged in?
$ w         # who is here and what are they doing?
$ id        # user ID, group ID, and groups you're in

Users have

Managing users

$ cat /etc/passwd
# username:x:UID:GID:GECOS:homedir:shell
$ useradd $USER # vs adduser, the friendly Ubuntu version
$ userdel $USER
$ passwd
_images/xkcd215.png
# GECOS: full name, office number and building, office phone extension,
# home phone number (General Electric Comprehensive Operating System)
$ chfn # change GECOS information; only works sometimes
$ finger # tells you someone's GECOS info

Passwords

test@x230 ~ $ ls -l /etc/ | grep shadow
-rw-r-----  1 root shadow   1503 Nov 12 17:37 shadow

$ sudo su -
$ cat /etc/shadow
daemon:*:15630:0:99999:7:::
bin:*:15630:0:99999:7:::
sys:*:15630:0:99999:7:::
mail:*:15630:0:99999:7:::

# name:hash:time last changed: min days between changes: max days
#    between changes:days to wait before expiry or disabling:day of
#    account expiry

$ chage # change when a user's password expires

Root/Superuser

_images/xkcd149.png

Acting as another user

$ su $USER          # become user, with THEIR password
$ su                # become root, with root's password
$ sudo su -         # use user password instead of root's
$ sudo su $USER     # become $USER with your password
_images/xkcd_838.png
If someone has permissions errors:
  • Check that they or their group owns the files
  • Check that they have the flag +x to execute

What are groups?

$ groupadd
$ usermod
$ groupmod
$ cat /etc/group
    root:x:0:
    daemon:x:1:
    bin:x:2:
    sys:x:3:
    adm:x:4:
    tty:x:5:
# group name:password or placeholder:GID:member,member,member

Hands-On: Users and Groups

Note

To give yourself sudo powers do the following:

  1. Add your user to the wheel group using gpasswd.

  2. As the root user, use visudo and uncomment this line:

    %wheel  ALL=(ALL)   ALL
    
  3. Save the file and now you should have sudo!

We'll cover sudo in more depth at a later time.

What are files?

test@x230 ~ $ ls -il
total 8
2884381 drwxrwxr-x 5 test test 4096 Nov  6 11:46 Documents
2629156 -rw-rw-r-- 1 test test    0 Nov 13 14:09 file.txt
2884382 drwxrwxr-x 2 test test 4096 Nov  6 13:22 Pictures

File extensions

$ file $FILENAME # tells you about the filetype

test@x230 ~ $ file file.txt
file.txt: ASCII text

test@x230 ~ $ file squirrel.jpg
squirrel.jpg: JPEG image data, JFIF standard 1.01

ls -l

$ ls -l
drwxrwxr-x 5 test test 4096 Nov  6 11:46 Documents
-rw-rw-r-- 1 test test    0 Nov 13 14:09 file.txt
drwxrwxr-x 2 test test 4096 Nov  6 13:22 Pictures

chmod and octal permissions

+=====+========+=======+
| rwx | Binary | Octal |
+=====+========+=======+
| --- | 000    | 0     |
| --x | 001    | 1     |
| -w- | 010    | 2     |
| -wx | 011    | 3     |
| r-- | 100    | 4     |
| r-x | 101    | 5     |
| rw- | 110    | 6     |
| rwx | 111    | 7     |
+=====+========+=======+

chown, chgrp

user & group

# Change the owner of myfile to "root".
$ chown root myfile

# Likewise, but also change its group to "staff".
$ chown root:staff myfile

# Change the owner of /mydir and subfiles to "root".
$ chown -hR root /mydir

# Make the group devops own the bootcamp dir
$ chgrp -R devops /home/$yourusername/bootcamp

Types of files

drwxrwxr-x      5 test    test      4096    Nov  6 11:46 Documents
-rw-rw-r--      1 test    test         0    Nov 13 14:09 file.txt
drwxrwxr-x      2 test    test      4096    Nov  6 13:22 Pictures
----------     -------  -------  -------- ------------ -------------
    |             |        |         |         |             |
    |             |        |         |         |         File Name
    |             |        |         |         +---  Modification Time
    |             |        |         +-------------   Size (in bytes)
    |             |        +-----------------------        Group
    |             +--------------------------------        Owner
    +----------------------------------------------   File Permissions

- is a normal file

d is a directory

b is a block device

ACLs

Hands-On: Files and Permissions

$ touch foo # create empty file called foo

Package Management

Take care of installation and removal of software

Core Functionality:

Popular Linux Package Managers

RPM & yum (RedHat, CentOS, Fedora)

_images/rpm.png

RPM

Binary file format which includes metadata about the package and the application binaries as well.
_images/yum.png

Yum

RPM package manager used to query a central repository and resolve RPM package dependencies.

Yum Commands (Redhat, CentOS, Fedora)

We'll use the tree package as an example below.

# Searching for a package
$ yum search tree

# Information about a package
$ yum info tree

# Installing a package
$ yum install tree

# Upgrade all packages to a newer version
$ yum upgrade

# Uninstalling a package
$ yum remove tree

# Cleaning the RPM database
$ yum clean all

RPM Commands

Low level package management. No dependency checking or central repository.

# Install an RPM file
$ rpm -i tree-1.5.3-2.el6.x86_64.rpm

# Upgrade an RPM file
$ rpm -Uvh tree-1.5.3-3.el6.x86_64.rpm

# Uninstall an RPM package
$ rpm -e tree

# Querying the RPM database
$ rpm -qa tree

# Listing all files in an RPM package
$ rpm -ql tree

DPKG & Apt (Debian, Ubuntu)

Deb

Binary file format which includes metadata about the package and the application binaries as well.
_images/debian.png

DPKG

Low level package installer for the .deb file format. Does no package dependency resolution.

Apt

DPKG package manager used to query a central repository and resolve Deb package dependencies. Considered mostly a front-end to dpkg.

Apt Commands (Debian, Ubuntu)

Note

You can also use aptitude as a front-end to dpkg instead of apt-get.

# Update package cache database
$ apt-get update

# Searching for a package
$ apt-cache search tree

# Information about a package
$ apt-cache show tree

# Installing a package
$ apt-get install tree

# Upgrade all packages to a newer version
$ apt-get upgrade
$ apt-get dist-upgrade

# Uninstalling a package
$ apt-get remove tree
$ apt-get purge tree

Dpkg Commands

Low level package management. No dependency checking or central repository.

# Install or upgrade a DEB file
$ dpkg -i tree_1.6.0-1_amd64.deb

# Removing a DEB package
$ dpkg -r tree

# Purging a DEB package
$ dpkg -P tree

# Querying the DPKG database
$ dpkg-query -l tree

# Listing all files in a DEB package
$ dpkg-query -L tree

Language-specific Package Managers

Other Package Managers

They each fill a specific niche and have their own pros and cons.

Installing from source

$ wget http://mirrors.kernel.org/gnu/grep/grep-2.15.tar.xz
$ tar -Jxvf grep-2.15.tar.xz
$ cd grep-2.15
$ ./configure
$ make
$ make install

Hands-on: Package Management

Questions: