Linux Administration Guide
This primarily discusses the options available to Ubuntu Linux server administrators. Have the operating system installed and then be logged in.
The "sudo" Command
sudo command is used to run commands with super user rights. Alternatively, to prevent having to use
sudo all the time login
in as the root user by issuing a
sudo -i or
sudo su command. To logout of the root user account issue a
exit again to logout the current user. Sometimes it is neccessary to be logged in as root.
On some Linux distributions, login as root with
su -nd then enter the password for root. Now, run all the following commands in this guide without
Changing the Computer's Clock
To change the computer's clock, issue
sudo hwclock --set --date "10/31/2017 24:00:00" and then to see the time it is set to
- To clear the screen simply issue the
- Issue a shutdown command with
sudo shutdown -h now. Issue a restart command with
sudo shutdown -r nowor
- Use the
envcommand to show all enviroment variables.
- To copy a file issue a
cp file1.txt file2.txt.
- To rename or move a file to another directory
mv old_name.txt new_name.txt.
- For a directory listing issue a
ls -alfor more detail. Issue
ls *.txtto list all text files.
- Change directory by issuing a
cd directorycommand. To change to the subdirectory issue
- To figure out the current directory
- To create a directory
- To delete a directory
- To delete a file
rm file.txt. Delete all files ending in .txt
rm *.txt. Enter
rm --helpfor more options.
- To create a user
sudo adduser michellethen, if it does not ask for the new user's password, immediately assign a password
sudo passwd michelle.
- Change a user's password with
sudo chpasswd username:newpassword.
- To delete a user
sudo deluser --remove-all-files --remove-home michelle.
- Issue a
ducommand to show disk usage.
findto search for files.
find --helpfor instructions.
chmodto modify file access permissions.
chmod --helpfor instructions.
chownto change the owner of a file/directory.
chown --helpfor instructions.
chgrpto change the group ownership of a file/directory.
chgrp --helpfor instructions.
manto display manual pages.
man --helpfor instructions.
topto show resource usage. q to quit this program.
- Issue a
cat file.txtto show the contents of a file. Use
less(covered below) to see large files.
whichtells the command that would be executed. Try
- Compare two files for differences:
diff file1.txt file2.txt.
- Compare two files for similarities:
comm file1.txt file2.txt.
- Use the
dfcommand to see disk space usage.
- Issue a
freecommand to determine free and used memory.
- Execute multiple commands seperating each by a semicolon, try:
w; du; free; ls
- For a list of the processes and the process ID (PID) issue a
pscommand. To stop a process issue a
sudo kill PIDcommand
pingcommand checks that an network interface is functioning properly. Try
ping -c 4 localhostor, if connected to the internet,
ping -c 4 www.ubuntu.com.
traceroutecommand follows the route that IP packets take. Try
Using the Text Editor "nano"
sudo nano file.txt command to edit a text file or create a text file. There is a menu of options at the bottom of the screen.
The "ifconfig" Command
ifconfig command to display all the networking interfaces installed in the computer including localhost
(also known as
lo). Change the IP address by issuing a
sudo ifconfig eth0 192.168.1.2 command. Change the netmask
by issuing a
sudo ifconfig eth0 netmask 255.255.255.0 command. Change the broadcast
by issuing a
sudo ifconfig eth0 broadcast 192.168.1.255 command.
Setting the Nameserver
sudo nano /etc/resolv.conf to edit the IP addresses for the nameservers.
nameserver 192.168.1.1 nameserver 18.104.22.168
Static IP Addresses
Login as the root user and issue a
nano /etc/network/interfaces command to edit the network interfaces to use a static IP address.
# The primary network interface auto eth0 iface eth0 inet static address 192.168.1.2 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 dns-nameservers 192.168.1.1 dns-search lan
The "less" Command
dmesg > outputdmesg.txt command then issue
less outputdmesg.txt. This will allow reading of the entire file as it is too big to fit on the
screen. q to quit the program.
Compressing/Decompressing Files with "tar"
To view the contents of a compressed archive
tar tzf archive.tgz or if it is a very large archive then
tar tzf archive.tgz | less. To create an
tar czf archivefilename.tgz directoryname. To decompress an archive
tar zxf archive.tgz.
The "man" Command
man command is used for reading online manuals. Execute
man man to read the manual for
Using "cron" to Repeatedly Execute Jobs
executes a task frequently. Users listed in the
cron.deny file aren't allowed to use
cron and users listed in the
cron.allow file are allowed.
The root user can always set jobs. Learn more by issuing a
man cron command.
To enable the firewall, issue a
sudo ufw enable command.
To enable a port
through the firewall, issue a
sudo ufw allow 587 command. To delete a port, issue
sudo ufw delete allow 587. Learn more by issuing a
man ufw command.
Updating the Server
sudo apt-get update,
sudo apt-get upgrade -y and
sudo apt-get dist-upgrade -y commands.
This will update the server software (if it needs it).
Installing and uninstalling software is done with the
sudo apt-get install and
sudo apt-get remove commands. For example, to install MySQL database
server issue the
sudo apt-get install mysql-server command. To remove it
sudo apt-get remove mysql-server.
Alternatively, a much simplier method is to use
sudo tasksel and then simply check (with the space key) what it is that you want installed or uninstalled.
/etc/init.d/apache2 status shows the current status (running or not).
sudo /etc/init.d/apache2 start will start Apache.
sudo /etc/init.d/apache2 stop will stop Apache.
sudo /etc/init.d/apache2 restart will restart Apache.
Configuration Files and Directories
/etc/apache2/apache2.conf: The main configuration file. It contains the generic configuration for the Apache web server, such as where to find its configuration files (
/etc/apache2/httpd.conf: At first, this file is empty. Create additional configuration parameters here that are not in the
/etc/apache2/ports.conf: This file contains the port numbers that the Apache server will listen on.
/etc/apache2/envvars: Place environment variables in this file to tune the operation of the web server.
/etc/apache2/conf.d/: Place additional configuration files in this directory.
/etc/apache2/mods-available/: Extend the functionality of the web server by using the modules available in this directory.
/etc/apache2/mods-enabled/: Enable a module by creating a symbolic link in this directory that refers to the module file in
/etc/apache2/mods-available/. To do so,
cd /etc/apache2/mods-enabled. To enable the
sudo ln -s ../mods-available/cache_disk.load cache_disk.load. Restart the web server.
/etc/apache2/sites-available/: Stores all the configuration files for the web sites serviced by the web server.
/etc/apache2/sites-enabled/: Contains symbolic links to the files in
/etc/apache2/sites-available/. To create a symbolic link
sudo ln -s ../sites-available/website.conf website.conf(make sure that
Install Samba server using the
sudo tasksel command.
Share a directory by editing the configuration file with the
sudo nano /etc/samba/smb.conf command. Page down to the
#=== Share Definitions === section and add these lines:
[www] path = /var/www/html writable = yes browseable = yes
Save the file and then issue a
sudo chmod 0777 /var/www/html command to set file permissions. Restart the server with
sudo service smbd restart and
sudo service nmbd restart.
Browse to the network on a Windows machine and the server should be listed with its new share, www, of the web server's home directory.
Now, learn how to install and setup a Ubuntu mail server.