Lesson 2: Single System Fundamentals
Or, how to be a power user.
Or, how to be a power user.
10 minutes to make sure everyone's Virtualbox instances are up and running
Your opinions:
$ 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
$ cat /etc/passwd
# username:x:UID:GID:GECOS:homedir:shell
$ useradd $USER # vs adduser, the friendly Ubuntu version
$ userdel $USER
$ passwd
# 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
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
$ 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
$ 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
Note
To give yourself sudo powers do the following:
Add your user to the wheel group using gpasswd.
As the root user, use visudo and uncomment this line:
%wheel ALL=(ALL) ALL
Save the file and now you should have sudo!
We'll cover sudo in more depth at a later time.
Nearly everything
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
.jpg, .txt, .doc
$ 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
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
+=====+========+=======+
| 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 |
+=====+========+=======+
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
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
$ touch foo # create empty file called foo
Take care of installation and removal of software
Core Functionality:
Popular Linux Package Managers
RPM
Binary file format which includes metadata about the package and the application binaries as well.
Yum
RPM package manager used to query a central repository and resolve RPM package dependencies.
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
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
Deb
Binary file format which includes metadata about the package and the application binaries as well.
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.
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
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
Languages sometimes have their own package management suite
Can be useful for using newer versions of packages
They each fill a specific niche and have their own pros and cons.
$ 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
read example output of ls -al
read output of yum or aptitude search