Linux Unit 2
Linux Unit 2
OVERVIEW
Red Hat Enterprise Linux, Fedora, and many other Linux distributions group their software together in
packages using what is referred to as RPM Package Manager (RPM). The "R" in RPM originally stood for
"Red Hat" but changed a few years ago to the recursive "RPM" to reflect the fact that other Linux
distributions besides Red Hat use this packaging system. If you are new to administering systems that use
RPM packaging, it is important that you understand what RPM packages are and how you work with them.
Using this tech brief as a tutorial you can learn about RPM packages and the commands for working with
those packages. The tech brief covers the following topics:
• What are RPM packages?
• How do you use the rpm command to install and query RPM packages on your local system?
• How do you use the yum command to download, install and otherwise manage RPM packages from
YUM software repositories?
• Get a RHEL installation DVD: If you have a Red Hat Enterprise Linux installation DVD, insert it and
wait for it to automatically mount. Then open a shell and change to the Packages directory on the
DVD (for example, cd /media/RHEL*/Packages).
For RHEL 6.3, the package name is amanda-2.6.1p2-7.el6.x86_64.rpm (the package you get may be
different, as later versions are released or if you have a different type of computer). Just from the name, you
can tell a lot about the package. Figure 1 illustrates the different parts of the amanda RPM package:
The basename of the package just shown is amanda. After that, the version number (2.6.1p2) is the version
assigned by the Amanda project (http://amanda.org), which tells us that the version number is 2.6.1, patch
level 2. The release information (7.el6) is added by the packager (in this case, Red Hat). The release shows
that this version of the package has been released 7 times (probably for bug fixes) and is associated with
Red Hat Enterprise Linux 6 (el6). This particular package was built for 64-bit PC-type architecture (x86_64).
• Querying a package (if the package is on your local file system or after the package is installed)
• Validating a package (checking a package has not been tampered with, before or after installation).
To query package, use the -q option to the rpm command, along with an indication of what you want to
query. To query a package before it is installed, add the -p option along with the package name as an
argument.
The amanda package contains the core AMANDA programs and will need to be installed
on both AMANDA clients and AMANDA servers. Note that you will have to install the
amanda-client and/or amanda-server packages as well.
You can read the Summary and Description to see what the package is used for. The URL identifies the web
site for the project (http://www.amanda.org). You can also see who created the RPM from this software (Red
Hat), as well as when and where the software was built. The Signature line shows that the package was
signed. This means that, if you have the public key associated with the private key used to sign the RPM,
you can check whether or not the package has been tampered with.
Now that you know basically what the package is for, use the following command to see what files the
package contains. First try the -l option to list the files the package contains:
The listing of files is shortened to save space. The full output shows that the package contains configuration
files, scripts use with amanda, and documentation. You can list some of that information separately. Here's
how to list configuration files in the amanda package:
Copyright © 2012 Red Hat, Inc. “Red Hat,” Red Hat Linux, the Red Hat “Shadowman” logo, and the products www.redhat.com
listed are trademarks of Red Hat, Inc., registered in the U.S. and other countries. Linux® is the registered
trademark of Linus Torvalds in the U.S. and other countries.
# rpm -qpd amanda-2.6.1p2-7.el6.x86_64.rpm
/usr/share/doc/amanda-2.6.1p2/COPYRIGHT
/usr/share/doc/amanda-2.6.1p2/NEWS |
/usr/share/doc/amanda-2.6.1p2/README
/usr/share/doc/amanda-2.6.1p2/README-rpm
/usr/share/man/man5/amanda-archive-format.5.gz
/usr/share/man/man5/amanda.conf.5.gz
/usr/share/man/man7/amanda-auth.7.gz
/usr/share/man/man7/amanda-scripts.7.gz
/usr/share/man/man8/amarchiver.8.gz
/usr/share/man/man8/amrestore.8.gz
To see changes and bug fixes associated with the package, type the following:
One thing you can do with the rpm command is check that the package itself is valid and not corrupted.
Because amanda is part of the base Red Hat Enterprise Linux system, the package is signed and can be
checked against a public key that should already be imported on your system. (For packages that you get
from other organizations, you might need to import additional keys to check the validity of packages.)
The following command shows how to validate the amanda package (assuming the public key for the key
used to sign the package has been imported and the amanda package is in your current directory):
From the rpm output, you can see the package listed as OK. I modified the package file (without modifying
the payload) and ran the command again. As you can see below, the package is NOT OK as it now stands:
In most cases, you should install packages using the yum command (as described later). However, in cases
where you have an RPM package available on your local system and there are not any components missing
on the system the package needs to work, you can use rpm to install the package. For example:
• Places the files the package contains into the proper locations in the file system.
• Stores the package's metadata in the local RPM database.
• In some cases, runs scripts to further configure the package.
Understanding RPM Packages | Chris Negus 4
After the package is installed, you can query information about the package from the local RPM database,
instead of from the package itself. To do this, you can drop the -p option from the query commands shown
earlier and use the package's basename. Here are some examples:
# rpm -qi amanda Query local RPM db for amanda information
# rpm -ql amanda Query local RPM db for all amanda files
# rpm -qc amanda Query local RPM db for amanda config files
# rpm -qd amanda Query local RPM db for amanda doc files
# rpm -q --changelog amanda Query local RPM db for amanda changes
If you are done with the amanda package, you can remove it using the rpm -e command:
# rpm -e amanda
To learn more about RPM Package Management and the rpm command, refer to Appendix B of the Red Hat
Enterprise Linux Deployment Guide:
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html-
single/Deployment_Guide/index.html#ch-RPM
While the rpm command is good for learning about RPM packages, the yum command (and related tools) is
usually the better command for installing packages.
Transaction Summary
==============================================================================
Install 2 Package(s)
Total download size: 749 k
Installed size: 0
Is this ok [y/N]: y
The yum install amanda-client command causes the yum command to search the YUM repository
(provided by Red Hat Network) to download and install the amanda-client package. Because amanda-client
requires components from the amanda package, that package is shown as required as well. Type y when
prompted and both software packages are downloaded and installed.
Here are some other yum command lines that might be useful to you:
There are other yum options available as well. See the yum man page (type man yum) for more information.
To learn other features of YUM, refer to Chapter 5 of the Red Hat Enterprise Linux Deployment Guide:
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html-
single/Deployment_Guide/index.html#ch-yum
The tar command on Linux is used to create and extract TAR archive files.
Run "tar -czvf (archive name).tar.gz (pathtofile)” in the Terminal to compress a file or
folder. To extract an archive to the current folder, run the command “tar -xzvf
(archive file)".
You can compress multiple directories or files at once by providing a list of files or
directories, and you can exclude certain files or directories using the --exclude switch.
The tar command on Linux is often used to create .tar.gz or .tgz archive files, also called
"tarballs." This command has a large number of options, but you just need to remember a few
letters to quickly create archives with tar. The tar command can extract the resulting archives,
too.
The GNU tar command included with Linux distributions has integrated compression. It can
create a .tar archive and then compress it with gzip or bzip2 compression in a single
command. That's why the resulting file is a .tar.gz file or .tar.bz2 file.
Let's say you have a directory named "stuff" in the current directory and you want to save it
to a file named archive.tar.gz. You'd run the following command:
Or, let's say there's a directory at /usr/local/something on the current system and you want to
compress it to a file named archive.tar.gz. You'd run the following command:
For example, let's say you want to compress /home/ubuntu, but you don't want to compress
the /home/ubuntu/Downloads and /home/ubuntu/.cache directories. Here's how you'd do it:
The --exclude switch is very powerful. It doesn't take names of directories and files — it
actually accepts patterns. There's a lot more you can do with it. For example, you could
archive an entire directory and exclude all .mp4 files with the following command:
Gzip is faster, but it generally compresses a bit less, so you get a somewhat larger file. Bzip2
is slower, but it compresses a bit more, so you get a somewhat smaller file. Gzip is also more
common, with some stripped-down Linux systems including gzip support by default, but not
bzip2 support. In general, though, gzip and bzip2 are practically the same thing, and both will
work similarly.
For example, instead of the first example we provided for compressing the stuff directory,
you'd run the following command:
It's the same as the archive creation command we used above, except the -x switch replaces
the -c switch. This specifies you want to extract an archive instead of create one.
You may want to extract the contents of the archive to a specific directory. You can do so by
appending the -C switch to the end of the command. For example, the following command
will extract the contents of the archive.tar.gz file to the /tmp directory.
If the file is a bzip2-compressed file, replace the "z" in the above commands with a "j".
This is the simplest possible usage of the tar command. The command includes a large
number of additional options, so we can't possibly list them all here. For more information.
run the info tar command at the shell to view the tar command's detailed information page.
Press the q key to quit the information page when you're done. You can also read tar's manual
online.
How to Add and Delete Users on Debian
Adding and deleting users is one of the most basic tasks when starting from a fresh Debian
server.
Adding user can be quite useful. As your host grows, you want to add new users, assign them
special permissions, like sudo rights for example.
In this tutorial, we are going all the ways to add and delete users on Debian hosts.
Table of Contents
Prerequisites
Adding a user using adduser
Adding a user using useradd
Add a user using the GNOME desktop
Check that your user was added
Deleting a user using deluser
Deleting a sudo user with visudo
Deleting a user using the GNOME Desktop
Troubleshooting
adduser : command not found on Debian
Prerequisites
In order to add and delete users on Debian, you need to have sudo rights, or to belong to the
sudo group.
$ sudo -v
If no error messages appear, you are good to go, otherwise ask your system administrator to
provide you with sudo rights.
The adduser command is very similar to the useradd command. However, it provides a more
interactive way to add users on a Debian host.
Generally, it is preferred to use adduser rather than useradd (as recommended by the useradd
man page itself)
Then you will be asked to specify some specific information about your new user.
You can leave some values blank if you want by pressing Enter.
Finally, you will be asked if the information provided is correct. Simply press “Y” to add
your new user.
Now that your user was created, you can add it to the sudo group.
To assign a password to the user, you can use the -p flag but it is not recommended as other
users will be able to see the password.
New password:
Retype new password:
passwd: password updated successfully
Enter your password, and a “Add User” option should now appear in the panel.
In the next window, choose what type of account you want for the user (either with sudo
rights or not).
You can choose to assign a password now or you can let the user decide on its password on
its next logon.
If there are no entries for the user you just created, make sure to use the adduser command
again.
To remove a user with its home directory, run the deluser command with the –remove-home
parameter.
To delete all the files associated with a user, use the –remove-all-files parameter.
$ sudo visudo
Find the line corresponding to the user you just deleted, and remove this line.
Save your file, and your user should not belong to the sudo group anymore.
When clicking on “Remove User”, you are asked if you want to keep the files owned by this
user. In this case, I will choose to remove the files.
Troubleshooting
In some cases, you may have some error messages when trying to execute some of the
commands above.
export PATH="$PATH:/usr/sbin/"
Source your bashrc file and try to run the adduser command again.
$ source ~/.bashrc
In today’s tutorial, we are going to see how you can add a user to sudoers on Debian
distributions.
The sudo command allows authorized users to perform commands as another user, which is
by default the root user.
There are two ways to add a user to sudoers : you can add this user to the sudo group or you
can add this user to the sudoers file located at etc.
Table of Contents
$ apt-get update
$ apt-get install sudo
To do that, you are going to use the “usermod” command with the capital G flag (for groups)
You can also use the gpasswd command to grand sudo rights.
Make sure that the user belongs to the sudo group with the groups command.
$ su - user
(password for user)
$ groups
user sudo
Depending on the configuration you chose during your Debian installation process, you may
or may not have access to a root account. If you chose a password for your root account, you
will be able to connect to it. Otherwise, the default admin account is the one you created
during the installation process.
This file contains a set of rules that are applied to determine who has sudo rights on a system,
which commands they can execute with sudo privileges, and if they should be prompted a
password or not.
However, you should never modify the sudoers file with a text editor.
Saving a bad sudoers may leave you with the impossibility of getting sudo rights ever again.
Instead, you are going to use visudo, a tool designed to make sure you don’t do any mistakes.
$ sudo visudo
By default, the account password will be asked every five minutes to perform sudo
operations.
However, if you want to remove this password verification, you can set the NOPASSWD option.
If you want the password verification to be skipped for longer periods of time, you can
overwrite the timestamp_timeout (in minutes) parameter in your sudoers file.
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
Defaults timestamp_timeout=30
This might be handy if you have a group for system administrators for example. In this case,
you simply have to add a user to the system administrators group for him/her to be granted
sudo privileges.
To add a group to the sudoers file, simply add a percent symbol at the beginning of the file.
Make sure that your user is part of the designed group with the groups command.
$ su - user
$ groups
user sysadmins
You can test your new sudo rights by changing your password for example
$ sudo passwd
By adding this user to the sudoers file on Debian, this error message should not be raised
anymore.