These are some personal notes I’m taking while learning linux administration. The books I am using are the following:
- Ubuntu Unleased
- Beginning Ubuntu LTS Server Administration
- The Official Ubuntu Server Book 2nd ed.
- UNIX and Linux System Administration Handbook (4th Edition)
- The shell is a command-line interface that interprets commands and translates them to machine code. It is an interface to the kernel which can be considered the heart of the Linux OS.
- The first shell was the Bourne shell. Bash stands for Bourne Again Shell and has many enhancements.
- The default shell is Dash, however the user root has Bash as its default shell.
- Use Tab key for automatic command completion
- History is useful for sessions beyond even the current one. To run any of the listed commands again, type its number preceded by an exclamation mark. This is why you cannot usually enter plain-text passwords (for security).
- gzip is the most popular compression utility, bzip2 compresses more but takes twice as long
- In case your Linux system is running under a graphical user interface (KDE, Gnome,…) and you need access to the console, use the Ctrl-Alt-F1 shortcut keys to switch to the first console. To switch back to Desktop mode, use the Ctrl-Alt-F7 shortcut keys.
- Nearly every command and application in Linux will have a man (manual) file, so finding them is as simple as typing man “command” to bring up a longer manual entry for the specified command.
- The tar command creates an archive (file), but this isn’t compressed. We need to use gzip or bzip2 to compress it.
- Piping sends the result of a command to another command.
- Redirection sends output of a command to a file or vice versa.
- Vim (VI improved) is an essential editor and you should learn how to use it at least at a basic level.
- Nano is a simpler editor.
- Automatic processes include services that are started automatically when you boot your server – they are known as daemons. Daemons are service processes that run in the background; in other words, they do not write their output directly to the standard output.
- Interactive processes are started by users from a shell. Any command started by a user and producing output on the standard output is an interactive process.
- Load averages are 3: the first for the last minute, the second for the last 5 minutes, and the third for the last 15 minutes.
- By default, syslog writes log messages to log files in the /var/log directory, in which you can find log information that is created in many different ways. One of the most important log files that you’ll find in this directory is /var/log/messages.
- To open mysql configuration file: nano /etc/mysql/my.cnf
- Different Linux distros have different default directory locations for serving domains also differs. Some default to /var/www/ and some to /srv/www/. Some organisations recommend /srv/domain.com/.
- Find a file: find / -name <name of file with extension>
- Location of php.ini: /etc/php5/apache2/php.ini
- To reboot: sudo reboot
- List of files in a directory: ls
- Switch to root: sudo su
- View all variables on a system: env
- To view all history commands: history
- Clear history: history -c
- Quit a command that is not responding: Ctrl+C
- Close a shell session/EOF signal: Ctrl+D
- Return to last directory: cd -
- Print working directory: pwd
- Create directory: mkdir (Force create inexisting parent dirs: mkdir -p)
- Remove directory: rmdir
- Remove non-empty directory: rm-rf
- Create a personal crontab configuration file: crontab -e
- Install FTP server: sudo apt-get install pure-ftpd
- Multiple terminal sessions: screen
- Restart Apache: sudo /etc/init.d/apache2 restart / sudo apache2ctl restart
- Start Text based browser: w3m <sitename>
- Display current kernel name: uname -r
How to use Screen for multiple CLI terminal sessions
To install a GUI on a server
Minimal Install: sudo aptitude install x-window-system-core gnome-core gdm firefox synaptic xubuntu-system-tools gnome-app-install
Some items install: sudo apt-get install gnome-desktop-environment
All Gnome: sudo aptitude install ubuntu-desktop
- aptitude install xorg xfce4
- aptitude install <name of GUI browser, I use firefox>
- aptitude install gedit
- aptitude install gnome-terminal
- and if you need it,
- aptitude install synaptic
- aptitude install xchat
- shutdown -r now
- List files: ls
- Remove files: rm
- Copy files: cp
- Move files: mv
- Create a text file: cat > foo.txt
- View text file: cat foo.txt
- Create empty file: touch foo.txt
- Open an advanced file viewer: less
- Display the first lines of a file: head
Graphical User Interfaces
- Install Openbox: sudo apt-get install xserver-xorg x-window-system-core openbox
- Uninstall Openbox: sudo apt-get purge openbox obconf obmenu
- Install GNOME Desktop Manager: sudo apt-get install xserver-xorg xfonts* gnome gdm
- Install Ubuntu Desktop: sudo apt-get install ubuntu-desktop
- tar is the most popular Linux backup utility (tape archiver = tar)
- tar -cvf somefile /somedirectory
- Find device is used by your server’s hard drive: sudo fdisk -l (the first drive listed is the local hard drive)
- To compress a file: gzip file.tar
- Virtual hosts allow you to server several sites from one instance of the Apache web server. To make this work, you need to set up DNS.
When working with virtual hosts, the following process is what happens when a user accesses the virtual host through the browseR:
- The user enters the URL in the browser.
- The DNS server redirects the user to your web server, based on the IP address that’s assigned by the name of the server at the requested URL.
- The request arrives at your server, which analyzes the port address the request is addressed to.
- Based on the port information, the request is sent to the Apache server, which analyses the request.
- Apache matches the name used in the URL and forwards the packet to the right virtual server.
Restart Apache: sudo /etc/init.d/apache2 restart
How to enable mod_rewrite: sudo a2enmod rewrite
Enabled or Disable modules: a2enmod / a2dismod
Partitioning the Drive
- / LVM ext4 50GB
- /home LVM ext4 varies
- /var LVM ext4 varies
- swap LVM swap 2xRAM
Installation of new server:
When ready, run the following:
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get install phpmyadmin
|Ctrl + A||Go to the beginning of the line you are currently typing on|
|Ctrl + E||Go to the end of the line you are currently typing on|
|Ctrl + L||Clears the Screen, similar to the clear command|
|Ctrl + U||Clears the line before the cursor position. If you are at the end of the line, clears the entire line.|
|Ctrl + H||Same as backspace|
|Ctrl + R||Let’s you search through previously used commands|
|Ctrl + C||Kill whatever you are running|
|Ctrl + D||Exit the current shell|
|Ctrl + Z||Puts whatever you are running into a suspended background process. fg restores it.|
|Ctrl + W||Delete the word before the cursor|
|Ctrl + K||Clear the line after the cursor|
|Ctrl + T||Swap the last two characters before the cursor|
|Esc + T||Swap the last two words before the cursor|
|Alt + F||Move cursor forward one word on the current line|
|Alt + B||Move cursor backward one word on the current line|
|Tab||Auto-complete files and folder names|
How to install Guest Additions for Ubuntu 11 in VirtualBox
Set Up an Ubuntu Server with Virtualbox
How to Build the Perfect Server
Making Ubuntu boot in the CLI
Modify your file
sudo update-grub. The machine will boot in text mode.
Then sudo gdm to start the GUI.
Set up Virtual Hosting on Ubuntu with Apache
To install phpmyadmin
- sudo apt-get install phpmyadmin
- gksudo gedit /etc/apache2/apache2.conf
- Add the following line of code inside apache2.conf:
- sudo /etc/init.d/apache2 restart
Using the hostname command
Webmin and Virtualmin
Multiple Hosts Layout for a VPS
- chgrp – Changes the group ownership of a file or directory
- chown – Changes the owner of a file or directory
- chmod – Changes the access permissions of a file or directory
- groupadd – This command creates and adds a new group
- groupdel – Removes an existing group
- groupmod – Creates a group name or GID but doesn’t add or delete members fro ma group
- gpasswd – Creates a group password. Every group can have a group password and an administrator. Use the -A argument to assign a user or group administrator.
- useradd – Adds a new user account to the system.
- useradd -G – The -G argument adds a user to a group during the initial user creation.
- usermod -G – This command allows you to add a user to a group so long as the user is not logged in at the time.
- userdel – Remove a user’s account
- passwd – Change the user password
- grpck – This command checks the /etc/group file for typos
To be able to update plugins, WP core, etc: sudo chown -R myusername:www-data public_html OR
sudo chown -R www-data:www-data public_html
Playing with Cron
Troubleshooting Memory and IO issues
When a process is slowing down a computer that has plenty of extra memory and disk space, it is probably because of cpu usage or input/output (I/O). Most users are used to using top to locate those pesky CPU and memory hogs, but few have ever used iotopto find the disk usage hogs.iotop displays columns for the I/O bandwidth read and written by each process/thread during the sampling period. It also displays the percentage of time the thread/process spent while swapping in and while waiting on I/O. In addition the total I/O bandwidth read and written during the sampling period is displayed at the top of the interface.
There are a few things you can do to try and figure out why the increased amounts of I/O occurred. The one would be to use the `iotop` utility when large amounts of disk I/O operations are occurring. There is not a way to track what caused the usage in the past, so you would need to catch them in the act with `iotop`.
Another thing to check would be your memory usage of your Linode. Depending on how your web server, PHP, and MySQL are configured it may not be optimized for the memory available to your Linode. If this is the case your Linode might be consuming all of the memory available and entering an out-of-memory (OOM) situation.
To see the current memory usage of your Linode you can issue this command:
A very good optimisation article: http://library.linode.com/troubleshooting/memory-networking
Linux Ram issues: http://www.linuxatemyram.com/
How to intsall APC Caching: http://www.electrictoolbox.com/install-apc-php-linux/
Shell scripts should always start with a shebang. The shebang consists of a pound sign followed by an exclamation mark, followed by the name of the required command interpreter. If the program that is referred to by the shebang is present on your system, the script will run, no matter what shell environment you’re currently in as a user.
To request the exit status of the last command executed by the shell: echo $?
To check whether the name of your script is already used by some other command: which
To execute a shell script:
- Activate it as an argument of your shell.
- “Source” the script.
- Make it executable and run it.