Category: Linux & Open Source

Linux administration on Ubuntu and CentOS: commands, scripting, networking, services (DNS, DHCP, Samba, NFS, Apache, Squid) and LPIC study notes.

  • Command Line Basics (ls, cat and echo)

    15 Basic ‘ls’ Command Examples in Linux

    ls command is one of the most frequently used command in Linux. I believe ls command is the first command you may use when you get into the command prompt of Linux Box. We use lscommand daily basis and frequently even though we may not aware and never use all the option available. In this article, we’ll be discussing basic ls command where we have tried to cover as much parameters as possible.

     

    1. List Files using ls with no option

    ls with no option list files and directories in bare format where we won’t be able to view details like file types, size, modified date and time, permission and links etc.

    # ls
    
    0001.pcap        Desktop    Downloads         index.html   install.log.syslog  Pictures  Templates
    anaconda-ks.cfg  Documents  fbcmd_update.php  install.log  Music               Public    Videos

    2 List Files With option –l

    Here, ls -l (-l is character not one) shows file or directory, size, modified date and time, file or folder name and owner of file and it’s permission.

    # ls -l
    
    total 176
    -rw-r--r--. 1 root root   683 Aug 19 09:59 0001.pcap
    -rw-------. 1 root root  1586 Jul 31 02:17 anaconda-ks.cfg
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Desktop
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Documents
    drwxr-xr-x. 4 root root  4096 Aug 16 02:55 Downloads
    -rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php
    -rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html
    -rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log
    -rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Music
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Pictures
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Public
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Templates
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Videos

    3. View Hidden Files

    List all files including hidden file starting with ‘.‘.

    # ls -a
    
    .                .bashrc  Documents         .gconfd          install.log         .nautilus     .pulse-cookie
    ..               .cache   Downloads         .gnome2          install.log.syslog  .netstat.swp  .recently-used.xbel
    0001.pcap        .config  .elinks           .gnome2_private  .kde                .opera        .spice-vdagent
    anaconda-ks.cfg  .cshrc   .esd_auth         .gtk-bookmarks   .libreoffice        Pictures      .tcshrc
    .bash_history    .dbus    .fbcmd            .gvfs            .local              .pki          Templates
    .bash_logout     Desktop  fbcmd_update.php  .ICEauthority    .mozilla            Public        Videos
    .bash_profile    .digrc   .gconf            index.html       Music               .pulse        .wireshark

    4. List Files with Human Readable Format with option -lh

    With combination of -lh option, shows sizes in human readable format.

    # ls -lh
    
    total 176K
    -rw-r--r--. 1 root root  683 Aug 19 09:59 0001.pcap
    -rw-------. 1 root root 1.6K Jul 31 02:17 anaconda-ks.cfg
    drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Desktop
    drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Documents
    drwxr-xr-x. 4 root root 4.0K Aug 16 02:55 Downloads
    -rw-r--r--. 1 root root  21K Aug 12 12:42 fbcmd_update.php
    -rw-r--r--. 1 root root  46K Jul 31 09:58 index.html
    -rw-r--r--. 1 root root  48K Jul 31 02:17 install.log
    -rw-r--r--. 1 root root  12K Jul 31 02:13 install.log.syslog
    drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Music
    drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Pictures
    drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Public
    drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Templates
    drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Videos

    5. List Files and Directories with ‘/’ Character at the end

    Using -F option with ls command, will add the ‘/’ Character at the end each directory.

    # ls -F
    
    0001.pcap        Desktop/    Downloads/        index.html   install.log.syslog  Pictures/  Templates/
    anaconda-ks.cfg  Documents/  fbcmd_update.php  install.log  Music/              Public/    Videos/

    6. List Files in Reverse Order

    The following command with ls -r option display files and directories in reverse order.

    # ls -r
    
    Videos     Public    Music               install.log  fbcmd_update.php  Documents  anaconda-ks.cfg
    Templates  Pictures  install.log.syslog  index.html   Downloads         Desktop    0001.pcap

    7. Recursively list Sub-Directories

    ls -R option will list very long listing directory trees. See an example of output of the command.

    # ls -R
    
    total 1384
    -rw-------. 1 root     root      33408 Aug  8 17:25 anaconda.log
    -rw-------. 1 root     root      30508 Aug  8 17:25 anaconda.program.log
    
    ./httpd:
    total 132
    -rw-r--r--  1 root root     0 Aug 19 03:14 access_log
    -rw-r--r--. 1 root root 61916 Aug 10 17:55 access_log-20120812
    
    ./lighttpd:
    total 68
    -rw-r--r--  1 lighttpd lighttpd  7858 Aug 21 15:26 access.log
    -rw-r--r--. 1 lighttpd lighttpd 37531 Aug 17 18:21 access.log-20120819
    
    ./nginx:
    total 12
    -rw-r--r--. 1 root root    0 Aug 12 03:17 access.log
    -rw-r--r--. 1 root root  390 Aug 12 03:17 access.log-20120812.gz

    8. Reverse Output Order

    With combination of -ltr will shows latest modification file or directory date as last.

    # ls -ltr
    
    total 176
    -rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog
    -rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log
    -rw-------. 1 root root  1586 Jul 31 02:17 anaconda-ks.cfg
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Desktop
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Videos
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Templates
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Public
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Pictures
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Music
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Documents
    -rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html
    -rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php
    drwxr-xr-x. 4 root root  4096 Aug 16 02:55 Downloads
    -rw-r--r--. 1 root root   683 Aug 19 09:59 0001.pcap

    9. Sort Files by File Size

    With combination of -lS displays file size in order, will display big in size first.

    # ls -lS
    
    total 176
    -rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log
    -rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html
    -rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php
    -rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Desktop
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Documents
    drwxr-xr-x. 4 root root  4096 Aug 16 02:55 Downloads
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Music
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Pictures
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Public
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Templates
    drwxr-xr-x. 2 root root  4096 Jul 31 02:48 Videos
    -rw-------. 1 root root  1586 Jul 31 02:17 anaconda-ks.cfg
    -rw-r--r--. 1 root root   683 Aug 19 09:59 0001.pcap

    10. Display Inode number of File or Directory

    We can see some number printed before file / directory name. With -i options list file / directory with inode number.

    # ls -i
    
    20112 0001.pcap        23610 Documents         23793 index.html          23611 Music     23597 Templates
    23564 anaconda-ks.cfg  23595 Downloads            22 install.log         23612 Pictures  23613 Videos
    23594 Desktop          23585 fbcmd_update.php     35 install.log.syslog  23601 Public

    11. Shows version of ls command

    Check version of ls command.

    # ls --version
    
    ls (GNU coreutils) 8.4
    Copyright (C) 2010 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Written by Richard M. Stallman and David MacKenzie.

    12. Show Help Page

    List help page of ls command with their option.

    # ls --help
    
    Usage: ls [OPTION]... [FILE]...

    13. List Directory Information

    With ls -l command list files under directory /tmp. Wherein with -ld parameters displays information of /tmp directory.

    # ls -l /tmp
    total 408
    drwx------. 2 narad narad   4096 Aug  2 02:00 CRX_75DAF8CB7768
    -r--------. 1 root  root  384683 Aug  4 12:28 htop-1.0.1.tar.gz
    drwx------. 2 root  root    4096 Aug  4 11:20 keyring-6Mfjnk
    drwx------. 2 root  root    4096 Aug 16 01:33 keyring-pioZJr
    drwx------. 2 gdm   gdm     4096 Aug 21 11:26 orbit-gdm
    drwx------. 2 root  root    4096 Aug 19 08:41 pulse-gl6o4ZdxQVrX
    drwx------. 2 narad narad   4096 Aug  4 08:16 pulse-UDH76ExwUVoU
    drwx------. 2 gdm   gdm     4096 Aug 21 11:26 pulse-wJtcweUCtvhn
    -rw-------. 1 root  root     300 Aug 16 03:34 yum_save_tx-2012-08-16-03-34LJTAa1.yumtx
    # ls -ld /tmp/
    
    drwxrwxrwt. 13 root root 4096 Aug 21 12:48 /tmp/

    14. Display UID and GID of Files

    To display UID and GID of files and directories. use option -n with ls command.

    # ls -n
    
    total 36
    drwxr-xr-x. 2 500 500 4096 Aug  2 01:52 Downloads
    drwxr-xr-x. 2 500 500 4096 Aug  2 01:52 Music
    drwxr-xr-x. 2 500 500 4096 Aug  2 01:52 Pictures
    -rw-rw-r--. 1 500 500   12 Aug 21 13:06 tmp.txt
    drwxr-xr-x. 2 500 500 4096 Aug  2 01:52 Videos

    15. ls command and it’s Aliases

    We have made alias for ls command, when we execute ls command it’ll take -l option by default and display long listing as mentioned earlier.

    # alias ls="ls -l"

    Note: We can see number of alias available in your system with below alias command and same can be unalias as shown below example.

    # alias
    
    alias cp='cp -i'
    alias l.='ls -d .* --color=auto'
    alias ll='ls -l --color=auto'
    alias ls='ls --color=auto'
    alias mv='mv -i'
    alias rm='rm -i'
    alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

    To remove an alias previously defined, just use the unalias command.

    # unalias ls

    13 Basic Cat Command Examples in Linux

    The cat (short for “concatenate“) command is one of the most frequently used command in Linux/Unix like operating systems. cat command allows us to create single or multiple files, view contain of file, concatenate files and redirect output in terminal or files. In this article, we are going to find out handy use of cat commands with their examples in Linux.

     

    General Syntax

    cat [OPTION] [FILE]...

    1. Display Contains of File

    In the below example, it will show contains of /etc/passwd file.

    # cat /etc/passwd
    
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/sbin/nologin
    narad:x:500:500::/home/narad:/bin/bash

    2. View Contains of Multiple Files in terminal

    In below example, it will display contains of test and test1 file in terminal.

    # cat test test1
    
    Hello everybody
    Hi world,

    3. Create a File with Cat Command

    We will create a file called test2 file with below command.

    # cat >test2

    Awaits input from user, type desired text and press CTRL+D (hold down Ctrl Key and type ‘d‘) to exit. The text will be written in test2 file. You can see contains of file with following cat command.

    # cat test2
    
    hello everyone, how do you do?

    4. Use Cat Command with More & Less Options

    If file having large number of contains that won’t fit in output terminal and screen scrolls up very fast, we can use parameters more and less with cat command as show above.

    # cat song.txt | more
    # cat song.txt | less

    5. Display Line Numbers in File

    With -n option you could see the line numbers of a file song.txt in the output terminal.

    # cat -n song.txt
    
    1  "Heal The World"
    2  There's A Place In
    3  Your Heart
    4  And I Know That It Is Love
    5  And This Place Could
    6  Be Much
    7  Brighter Than Tomorrow
    8  And If You Really Try
    9  You'll Find There's No Need
    10  To Cry
    11  In This Place You'll Feel
    12  There's No Hurt Or Sorrow

    6. Display $ at the End of File

    In the below, you can see with -e option that ‘$‘ is shows at the end of line and also in space showing ‘$‘ if there is any gap between paragraphs. This options is useful to squeeze multiple lines in a single line.

    # cat -e test
    
    hello everyone, how do you do?$
    $
    Hey, am fine.$
    How's your training going on?$
    $

    7. Display Tab separated Lines in File

    In the below output, we could see TAB space is filled up with ‘^I‘ character.

    # cat -T test
    
    hello ^Ieveryone, how do you do?
    
    Hey, ^Iam fine.
    ^I^IHow's your training ^Igoing on?
    Let's do ^Isome practice in Linux.

    8. Display Multiple Files at Once

    In the below example we have three files test, test1 and test2 and able to view the contains of those file as shown above. We need to separate each file with ; (semi colon).

    # cat test; cat test1; cat test2
    
    This is test file
    This is test1 file.
    This is test2 file.

    9. Use Standard Output with Redirection Operator

    We can redirect standard output of a file into a new file else existing file with ‘>‘ (greater than) symbol. Careful, existing contains of test1 will be overwritten by contains of test file.

    # cat test > test1

    10. Appending Standard Output with Redirection Operator

    Appends in existing file with ‘>>‘ (double greater than) symbol. Here, contains of test file will be appended at the end of test1 file.

    # cat test >> test1

    11. Redirecting Standard Input with Redirection Operator

    When you use the redirect with standard input ‘<‘ (less than symbol), it use file name test2 as a input for a command and output will be shown in a terminal.

    # cat < test2
    
    This is test2 file.

    12. Redirecting Multiple Files Contain in a Single File

    This will create a file called test3 and all output will be redirected in a newly created file.

    # cat test test1 test2 > test3

    13. Sorting Contains of Multiple Files in a Single File

    This will create a file test4 and output of cat command is piped to sort and result will be redirected in a newly created file.

    # cat test test1 test2 test3 | sort > test4

    This article shows the basic commands that may help you to explore cat command. You may refer man page of cat command if you want to know more options.

    15 Practical Examples of ‘echo’ command in Linux

    echo is one of the most commonly and widely used built-in command for Linux bash and C shells, that typically used in scripting language and batch files to display a line of text/string on standard output or a file.

     

    The syntax for echo is:

    echo [option(s)] [string(s)]
    

    1. Input a line of text and display on standard output

    $ echo Tecmint is a community of Linux Nerds 
    

    Outputs the following text:

    Tecmint is a community of Linux Nerds 
    

    2. Declare a variable and echo its value. For example, Declare a variable of x and assign its value=10.

    $ x=10
    

    echo its value:

    $ echo The value of variable x = $x 
    
    The value of variable x = 10 
    

    Note: The ‘-e‘ option in Linux acts as interpretation of escaped characters that are backslashed.

    3. Using option ‘\b‘ – backspace with backslash interpretor ‘-e‘ which removes all the spaces in between.

    $ echo -e "Tecmint \bis \ba \bcommunity \bof \bLinux \bNerds" 
    
    TecmintisacommunityofLinuxNerds 
    

    4. Using option ‘\n‘ – New line with backspace interpretor ‘-e‘ treats new line from where it is used.

    $ echo -e "Tecmint \nis \na \ncommunity \nof \nLinux \nNerds" 
    
    Tecmint 
    is 
    a 
    community 
    of 
    Linux 
    Nerds 
    

    5. Using option ‘\t‘ – horizontal tab with backspace interpretor ‘-e‘ to have horizontal tab spaces.

    $ echo -e "Tecmint \tis \ta \tcommunity \tof \tLinux \tNerds" 
    
    Tecmint 	is 	a 	community 	of 	Linux 	Nerds 
    

    6. How about using option new Line ‘\n‘ and horizontal tab ‘\t‘ simultaneously.

    $ echo -e "\n\tTecmint \n\tis \n\ta \n\tcommunity \n\tof \n\tLinux \n\tNerds" 
    
    	Tecmint 
    	is 
    	a 
    	community 
    	of 
    	Linux 
    	Nerds 
    

    7. Using option ‘\v‘ – vertical tab with backspace interpretor ‘-e‘ to have vertical tab spaces.

    $ echo -e "\vTecmint \vis \va \vcommunity \vof \vLinux \vNerds" 
    
    Tecmint 
            is 
               a 
                 community 
                           of 
                              Linux 
                                    Nerds 
    
    

    8. How about using option new Line ‘\n‘ and vertical tab ‘\v‘ simultaneously.

    $ echo -e "\n\vTecmint \n\vis \n\va \n\vcommunity \n\vof \n\vLinux \n\vNerds" 
    
    
    Tecmint 
    
    is 
    
    a 
    
    community 
    
    of 
    
    Linux 
    
    Nerds 
    

    Note: We can double the vertical tab, horizontal tab and new line spacing using the option two times or as many times as required.

    9. Using option ‘\r‘ – carriage return with backspace interpretor ‘-e‘ to have specified carriage return in output.

    $ echo -e "Tecmint \ris a community of Linux Nerds" 
    
    is a community of Linux Nerds 
    

    10. Using option ‘\c‘ – suppress trailing new line with backspace interpretor ‘-e‘ to continue without emitting new line.

    $ echo -e "Tecmint is a community \cof Linux Nerds" 
    
    Tecmint is a community avi@tecmint:~$ 
    

    11. Omit echoing trailing new line using option ‘-n‘.

    $ echo -n "Tecmint is a community of Linux Nerds" 
    Tecmint is a community of Linux Nerdsavi@tecmint:~/Documents$ 
    

    12. Using option ‘\a‘ – alert return with backspace interpretor ‘-e‘ to have sound alert.

    $ echo -e "Tecmint is a community of \aLinux Nerds" 
    Tecmint is a community of Linux Nerds
    

    Note: Make sure to check Volume key, before firing.

    13. Print all the files/folder using echo command (ls command alternative).

    $ echo * 
    
    103.odt 103.pdf 104.odt 104.pdf 105.odt 105.pdf 106.odt 106.pdf 107.odt 107.pdf 108a.odt 108.odt 108.pdf 109.odt 109.pdf 110b.odt 110.odt 110.pdf 111.odt 111.pdf 112.odt 112.pdf 113.odt linux-headers-3.16.0-customkernel_1_amd64.deb linux-image-3.16.0-customkernel_1_amd64.deb network.jpeg 
    

    14. Print files of a specific kind. For example, let’s assume you want to print all ‘.jpeg‘ files, use the following command.

    $ echo *.jpeg 
    
    network.jpeg 
    

    15. The echo can be used with redirect operator to output to a file and not standard output.

    $ echo "Test Page" > testpage 
    
    ## Check Content
    avi@tecmint:~$ cat testpage 
    Test Page 
    
    echo Options
     Options  Description
     -n  do not print the trailing newline.
     -e  enable interpretation of backslash escapes.
     \b  backspace
     \\  backslash
     \n  new line
     \r  carriage return
     \t  horizontal tab
     \v  vertical tab

    How to display a list of recent commands in Ubuntu Linux

    Linux has a rich command line experience that can sometimes be a little daunting for people switching over from Windows. Displaying the list of recent commands is pretty simple, though:

    > history

    1 ps -ef
    2 kill 24188
    3 ps -ef
    4 tail logfile.log

    If you want to find a command that you used before but you have a huge history list, you can quickly find it by passing it through grep. Let’s say we remember typing the ftp command, but can’t remember the domain name of the server:

    > history | grep ftp

    321 ftp ftp.cdrom18.com

    Pretty simple stuff! What if we want to display the list of items that we use the most often?  We can use a much more complicated command like this:

    > history|awk ‘{print $2}’|awk ‘BEGIN {FS=”|”} {print $1}’|sort|uniq -c|sort -r

    114 ls
    105 ./runreports.sh
    97 cd
    24 uptime
    15 mysql
    13 vi

  • Difference between terminal and console

    The short answer is that

    • terminal = text input/output environment
    • console = physical terminal
    • shell = command line interpreter

    In the linux world they can all look the same from the point of view of the user at the keyboard. The differences are in how they interact with each other.

    The shell is the program which actually processes commands and returns output. Most shells also manage foreground and background processes, command history and command line editing. These features (and many more) are standard in bash, the most common shell in modern linux systems.

    A terminal refers to a wrapper program which runs a shell. Decades ago, this was a physical device consisting of little more than a monitor and keyboard. As unix/linux systems added better multiprocessing and windowing systems, this terminal concept was abstracted into software. Now you have programs such as Gnome Terminal which launches a window in a Gnome windowing environment which will run a shell into which you can enter commands.

    The console is a special sort of terminal. Historically, the console was a single keyboard and monitor plugged into a dedicated serial console port on a computer used for direct communication at a low level with the operating system. Modern linux systems provide virtual consoles. These are accessed through key combinations (e.g. Alt+F1 or Ctrl+Alt+F1; the function key numbers different consoles) which are handled at low levels of the linux operating system — this means that there is no special service which needs to be installed and configured to run. Interacting with the console is also done using a shell program.

  • Linux Desktop Environments and Desktop Managers

    Untitled

    GNOME Shell

    Five Best Linux Desktop Environments

    GNOME is one of the oldest Linux desktop environments, and certainly one of the most popular. GNOME—specifically GNOME Shell, the most recent iteration of the platform—has been designed to be easy to use, modern looking and attractive, and easy to customize and personalize. The break between GNOME 2 and GNOME Shell (the UI in version 3) upset many users, with several preferring the flatter, classic look of the DE and others preferring the more modern and less dated look of the most recent iteration. In any case, GNOME Shell has all the features you would expect from a DE, including a customizable application launcher, a top menu and status bar, system-wide search in the form of Dash, a window, application, and file manager, a notifications tray, and more. It even has window “snapping,” similar to Windows 7’s Aero Snap, support for touchpads and multi-touch gestures, and tons of extensions and system add-ons, widgets, and shell themes thanks to its broad adoption and huge user community. Even if you don’t prefer GNOME Shell, countless other DEs and offshoots are based on previous iterations of GNOME, so you’re likely using it as a bedrock for your preferred DE in some form or fashion.

    Those of you who nominated GNOME did so in a couple of threads, some of you highlighting specifically that you preferred it in Classic Mode, so it looks a bit more like GNOME 2, and others praising the way it handles features like virtual desktops, system settings and customization options, and desktop search. It also doesn’t hurt that GNOME has its own stable of supported apps rolled in, many of which are some of the best in their categories. Some of you called GNOME Shell out for performance issues, especially with the newer, more graphically heavy versions, but that’s been a topic for debate in the nomination threads.


    Cinnamon

    Five Best Linux Desktop Environments

    Originally developed as part of Linux Mint and a fork of GNOME Shell, Cinnamon grew into a desktop environment that’s portable, good looking, feature-rich, and compatible with just about every popular Linux distro. It’s based on the GTK+ 3 toolkit, and compatible with everything from its original home, Linux Mint, to other distros like Arch and Fedora. Cinnamon has been praised for bringing a very Windows-like UI to Linux, which breaks down the door to users who may be intimidated by the unfamiliar look and feel of other distributions and their interfaces. You get a customizable, easy to use menu from which to launch applications, and a bar across the bottom to switch between applications, and a tray that shows you applications in the background. Beyond that, Cinnamon customizable interface elements like that application menu that are movable around the screen, customizable applets and desktop extensions, themes, and more. It’s simple and elegant, although certainly not for everyone.

    Those of you who nominated Cinnamon recalled its roots in GNOME Shell. Many of you specifically noted that it was great for getting people comfortable with Linux who may not be or may be intimidated by it. Others of you mentioned specifically that Mint works so well because it’s simple, customizable, looks great, and works smoothly, so you choose it for those reasons—not because you want to spend a lot of time getting your DE running and looking like a modern operating system.


    Xfce

    Five Best Linux Desktop Environments

    Xfce is a lightweight desktop environment that’s based on the GTK+ 2, and built for Linux, Solaris, and BSD-based systems. It’s fast, flexible, actively updated, and designed to be fast and light on system resources, so your system doesn’t drag down just because your DE is heavy with graphical elements and effects. That doesn’t mean that Xfce is barebones though—it’s anything but. The UI is sharp and modern, looks great, and is overall user friendly. Xfce comes with all of the basic features you’d want in a desktop environment, including a panel for managing system settings and tweaks, window and desktop managers, a simple file manager, and an application launcher. Perhaps best of all though, Xfce is slim enough that you can load it up with your own customization elements to add to or replace the built-in ones and still wind up using less resources than some other DEs. Several distros even use Xfce as the default, including Xubuntu, Manjaro Linux, Mythbuntu, and more. Even where it’s not the default, it’s available as an option.

    XFCE turned up a couple of times in our nominations thread, most often with you mentioning your preferred distribution along with it. Putting all of those nominees together, and it was clearly one of the most popular DEs you guys mentioned. Some of you preferred it with Xubuntu, some of you added it to Linux Mint, and others slapped it on top of Compiz and went to town. All of you praised it for being super lightweight and adaptable even to embedded and really old (or just light service) hardware. At least one of you pointed out that you loved the fact that Xfce’s file explorer is a root file explorer, which is definitely a nice touch.


    KDE

    Five Best Linux Desktop Environments

    KDE is actually a collection of applications called the KDE Software Compilation, of which the desktop environment is just one. The original DE, first called the K Desktop Environment back in the day, was originally designed to give Linux desktop applications and tools a unifying look and feel, as well as to make them easier to use all-around. KDE uses the Qt framework. One of the best things about KDE is that not only do you get a desktop environment when you use it, you also open the door to an entire OS’s worth of additional applications, utilities, and tools that play nicely with the DE, work in the Qt framework, and are equally easy to install and regularly updated. The current iteration of the DE, “Plasma,” has variants for fully-featured systems where you want a more traditional interface, and a small-screen version for netbooks and other lightweight uses. KDE looks great, offers an extremely well polished experience, and doesn’t skimp on the customization and personalization aspects. From widgets to whole themes, you can make KDE your own pretty easily, and the fact that there’s a massive development and enthusiast community behind it doesn’t hurt either.

    Those of you who nominated KDE highlighted it’s long tradition, and praised it for its good looks, sharp design, and attention to detail. Many of you highlighted the fact that you can download themes, wallpapers, and other customization elements easily without ever opening a web browser, and others of you noted that you’d defected from other GNOME-based DEs. Others of you praised it for its wide app support, and support for apps you may not be able to get working in other DEs. It’s not the most lightweight option in the top five, but it was certainly one of the most well loved.


    Unity

    Five Best Linux Desktop Environments

    Unity is a graphical desktop environment based on GNOME Shell. It was developed byCanonical specifically for use with Ubuntu Linux, and debuted in a netbook/lightweight version of Ubuntu before making its way to the desktop version. Unlike other DEs, Unity isn’t a collection of applications or tools designed to complete a user experience—instead it’s designed to be an interface that work with whatever other applications you download and install, and it makes those applications easier to find. Unity is controversial to say the least—many people consider it bloated and slow, others consider it a beautiful and polished user experience. Part of Unity’s allure is that it provides a single user experience that works just as well on keyboard/mouse, touchscreen, and touchpad environments. It’s not feature light, to be fair—it comes with its own integrated desktop search tool and launcher in the form of Dash, Unity Preview, which is similar to OS X’s QuickLook, a top menu bar and a launcher along the left side of the screen, and integrated application finder, and built-in web search. Even so, Unity’s interface and design has turned off a number of users, and it remains an environment available largely for Ubuntu users, with elements of it available in other distributions, but none of them officially supporting Unity entirely.

    Those of you who nominated Unity—and supported its nomination—explicitly said that you knew that its inclusion would be controversial, but sure enough it collected enough nominations to get into the top five on its own. You praised Unity for simple and easy to use keyboard commands for search and app launching, and smart search terms that will put you in the right direction even if you’re not searching for exactly the thing you’re looking for. Some of you noted it can be slow, and lacks some of the full and rich customization options available in other DEs, while others of you noted that it’s a great option for people familiar with Windows looking for something like what they’re used to. Read more in its nomination thread here.

  • Ubuntu Software Center – Install And Remove Applications

    This tutorial’s intention is to teach newbies how to download, install and remove software in Ubuntu. I know this tutorial is for newbies like my Grandmother, but if we geeks don’t help newbies, who is going to help them?

    When I first heard about Ubuntu I didn’t even know how to delete items. I was used to having a recycle bin in Windows OS and I did not know about Trash in Ubuntu. “Linux is very hard to use.”. “Terminal, terminal…”. These words haunted me until I learned about Software Center.

    There are many people like my Father out there who want to learn Linux and this is the right article for them. How can my Father install software from the terminal when he does not know what a terminal is? Installing applications has been a difficult task and it scares away a lot of new users to Ubuntu, but Software Center makes the installation process dramatically easy.

    Find the application you want, click and install. You got to thank Ubuntu Software Center for making application installation so easy. Also, Software Center helps you to find the software you need and does not allow you to get lost in the ocean of search engines. Software Center was originally codenamed AppCenter and it is coded in my favorite programming language, Python. The goal of Software Center is to give the user a comfortable environment for downloading, installing and removing software and packages.

    Geeks love to type terminal commands to perform their tasks, but normal users want an easy way to install or remove applications. Click on ‘Install’ and the software is installed,. Click on ‘Remove’ and the software is removed. This is the way to go for beginners.

    You will need an internet connection in order to download and install applications from Software Center. Most applications are free and licensed under GPL license. You can launch Software Center by clicking on its icon and after you launch, it will look as shown in Figure 1.

    Figure 1

    You can perform advanced application search by using the list of categories  on the left of Software Center. To install a new software, type the name of the software you want to install in the search box like shown in Figure 2.

    Figure 2

    Click on the software title to get more info or install it like shown in Figure 3.

    Figure 3

    Figure 4

    To install VLC Media Player, I click ‘Install’. Software Center now prompts me for a password and I type my password. Then Software Center starts downloading the software and it shows a progress bar which gives you information about the download.

    After the download is finished the software installation starts. Now, if I am bored with VLC Media Player and want to remove it, I type VLC in the Search Box, click on the software and click ‘Remove’. If you ask me to define Ubuntu Software Center in three words, I would say “Smart, simple and sexy!”.

    I hope this helps beginners become familiar in how to use Software Center to Install and Remove software and packages in Ubuntu.

  • Major Open source (Linux) Applications

    Linux is embedded in:
    Roku
    Chromebooks
    Kindle
    Android Phones
    PS4 runs Orbis OS, a modified version of FreeBSD that’s similar to Linux

    ESXi

    Factory autmation

    Raspberry Pi

    Mars Rovers

    Linux Firewalls:
    Smoothwall
    PfSense
    Monowall

    Major open source applications:
    Apache
    Libre Office
    Samba
    NFS
    MySQL
    Postfix
    Firefx
    OpenOffice
    THunderbird
    Chromium
    Webmin
    SSH Clients
    Mobile Browsers
    C
    C++
    PHP
    Perl
    Shell
    Java

  • How To Install Webmin with SSL on Ubuntu 14.04

    Introduction

    Webmin is a web-based system administration tool for Unix-like systems. It provides an easy alternative to command line system administration and can be used to manage various aspects of a system, such as users and services, through the use of the provided Webmin modules. If you want to manage your own server but you are uncomfortable with the command line, Webmin is a good tool to help you get started.

    This tutorial covers the installation of Webmin with SSL using apt-get on Ubuntu 14.04.

    Prerequisites

    To install Webmin, you will need to have access to a user with root privileges. It is recommended that you set up a non-root user with sudo access by following steps 1-3 of this link: Initial Server Setup with Ubuntu 14.04. This user will also be used to login to the Webmin interface, and Webmin will use the credentials to administer your server.

    Note that you are required to use password-based authentication enabled to log in to your server via Webmin.

    Log in Via SSH

    Log in to your server as the new user that you created (or root) via SSH (substitute your user name and server IP address here):

    ssh new_user@server_IP_address
    

    Answer the password prompt to complete the login process.

    Let’s get started with the Webmin installation!

    Install Webmin

    To install Webmin via apt-get, you must first add the Webmin repository to your sources.list file.

    On your server, open the sources.list file in your favorite text editor. We will use nano in this tutorial:

    sudo nano /etc/apt/sources.list
    

    If you are prompted for a “[sudo] password”, enter your user’s password.

    Now press Ctrl-W then Ctrl-V to navigate to the end of the file, then add the following lines to the file:

    deb http://download.webmin.com/download/repository sarge contrib
    deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib
    

    When you are finished editing, save the file by pressing Ctrl-X, then y, RETURN.

    Now add the Webmin GPG key to apt, so the source repository you added will be trusted. This command will do that:

    wget -q http://www.webmin.com/jcameron-key.asc -O- | sudo apt-key add -
    

    Before installing Webmin, you must update apt-get’s package lists:

    sudo apt-get update
    

    Now run this apt-get command to install Webmin:

    sudo apt-get install webmin
    

    Enter y to confirm the installation.

    After the installation is complete, the Webmin service will start automatically.

    Log in to Webmin

    In a web browser, access your server’s Webmin login page via its public IP address (the same IP address you used to login via SSH) on port 10000. By default, Webmin will start with SSL/TLS enabled, so you will need to use HTTPS to connect to it.

    Open this URL in your web browser (substitute the IP address):

    https://server_IP_address:10000
    

    You will be prompted with a warning that says your server’s SSL certificate is not trusted. This is because Webmin automatically generates and installs an SSL certificate upon installation, and this SSL certificate was not issued by a certificate authority that is trusted by your computer. Although your computer cannot verify the validity of the certificate, you know that you are, in fact, accessing your own server. It is fine to proceed.

    Instruct your web browser to trust the certificate. If you are using Chrome, for example, click the Advancedlink, then click the Proceed to serverIPaddress (unsafe) link. If you are using Firefox, click I Understand the Risks, then the Add Exception… button, then the Confirm Security Exception button.

    At this point, you will see the Webmin login screen:

    Webmin login screen

    Enter the same login credentials that you used to log in to your server via SSH. This user must have rootprivileges via sudo.

    Congratulations! You have successfully installed Webmin, and it is ready to be used. Remember that, because you are using a privileged user to access Webmin, the Webmin application has full access to your server—keep your login credentials secure!

    Using Webmin

    When you first log into Webmin, you will be taken to the System Information page, which will show you an overview of your system’s resources and other miscellaneous information. This view also shows you any Webmin updates that are available.

    Webmin Dashboard

    On the left side, you will see the navigation menu, which you can use to access the various Webmin modules and manage your server. The navigation menu is organized into categories, and each category has its own set of modules. The Webmin category is special because contains modules that are used to configure the Webmin application, while the other categories are used to perform various system administration tasks.

    Take some time to explore the modules that are available, to familiarize yourself with Webmin.

    Example: Create a New User

    A basic system administration task that you can perform with Webmin is user management. We will show you how to create a new user with the Users and Groups module.

    Expand the System category in the navigation menu, then click on Users and Groups.

    Then click the Create a new user. link.

    Create user

    Enter the Username and any other settings you want to assign to the new user, then click the Createbutton.

    The user will be created on the server, with the specified settings.

    The Users and Groups module can also be used to perform other user management tasks, such as deleting and disabling users and groups.

    Example: Install Apache

    Webmin comes with a large variety of modules that manage different software packages. We will demonstrate how to install a web server using the the Apache Webserver module, as an example.

    In the navigation menu, click Un-used Modules to expand the category, and then click Apache Webserver.

    If you do not have Apache installed on your server, the module will notify you and provide you with a way to install Apache.

    Use the Click here link (in the last sentence) to install Apache via apt-get through Webmin.

    After the Apache installation is complete, your server will be running the default Apache server.

    The Apache Webserver module will be moved to the Servers category, and you may use it to manage the configuration of your Apache server.

    Conclusion

    Now that you have Webmin installed on your Ubuntu server, you should be able to use it to perform basic system administration tasks.

    Good luck!

  • How to Install and Configure phpMyAdmin on Ubuntu 14.04

    phpMyAdmin is an open source tool used for the administration of MySQL. In addition to offering the capability to perform administration tasks such as creating, editing, or deleting databases, and managing users and permissions, phpMyAdmin provides a graphical user interface to do all of these tasks and more.

    Pre-Flight Check
    • These instructions are intended specifically for installing phpMyAdmin on Ubuntu 14.04 LTS.
    • I’ll be working from a Liquid Web Core Managed Ubuntu 14.04 LTS server, and I’ll be logged in as root.
    • A LAMP, Linux, Apache, MySQL and PHP, must be installed on your server. If you’re working from a Liquid Web Core Managed Ubuntu 14.04 LTS server as I am, then the LAMP stack is already installed!
    Step 1: Install phpMyAdmin

    First, you’ll follow a simple best practice: ensuring the list of available packages is up to date before installing anything new.

    apt-get -y update

    Then it’s a matter of just running one command for installation via apt-get:

    apt-get -y install phpmyadmin

    Step 2: Basic Configuration

    As the installation runs you’ll be asked a few simple questions regarding the basic configuration of phpMyAdmin.

    At the first screen, select apache2 by using the space bar, then hit enter to continue.

    How To Install and Secure phpMyAdmin on Ubuntu 12.04

    At the second screen, which asks “configure the database for phpmyadmin with dbconfig-common?”, select Yes , then hit enter to continue.

    How to Install and Secure phpMyAdmin on Ubuntu 12.04

    At the third screen enter your MySQL password, then hit enter to continue.

    How to Install and Secure phpMyAdmin on Ubuntu 12.04

    And finally at the fourth screen set the password you’ll use to log into phpmyadmin, hit enter to continue, and confirm your password.

    How to Install and Secure phpMyAdmin on Ubuntu 12.04

    Step 3: Finish the Configuration of Apache

    For a refresher on editing files with vim see: New User Tutorial: Overview of the Vim Text Editor

    vim /etc/apache2/apache2.conf

    Add the following to the bottom of the file:

    # phpMyAdmin Configuration
    Include /etc/phpmyadmin/apache.conf

    Then exit and save the file with the command :wq .

    And, restart Apache 2 with the following command:

    service apache2 restart

    Verify that phpMyAdmin is working by visiting the_IP_of_your_server/phpmyadmin. For example: http://127.0.0.1/phpmyadmin

    http://domain_name_or_IP/phpmyadmin
    

    phpmyadmin login screen

    You can now log into the interface using the root username and the administrative password you set up during the MySQL installation.

    When you log in, you’ll see the user interface, which will look something like this:

    phpmyadmin user interface

    Step Two — Secure your phpMyAdmin Instance

    We were able to get our phpMyAdmin interface up and running fairly easily. However, we are not done yet. Because of its ubiquity, phpMyAdmin is a popular target for attackers. We need to secure the application to help prevent unauthorized use.

    One of the easiest way of doing this is to place a gateway in front of the entire application. We can do this using Apache’s built-in .htaccess authentication and authorization functionalities.

    Configure Apache to Allow .htaccess Overrides

    First, we need to enable the use of .htaccess file overrides by editing our Apache configuration file.

    We will edit the linked file that has been placed in our Apache configuration directory:

    sudo nano /etc/apache2/conf-available/phpmyadmin.conf
    

    We need to add an AllowOverride All directive within the <Directory /usr/share/phpmyadmin>section of the configuration file, like this:

    <Directory /usr/share/phpmyadmin>
        Options FollowSymLinks
        DirectoryIndex index.php
        AllowOverride All
        . . .
    

    When you have added this line, save and close the file.

    To implement the changes you made, restart Apache:

    sudo service apache2 restart
    

    Create an .htaccess File

    Now that we have enabled .htaccess use for our application, we need to create one to actually implement some security.

    In order for this to be successful, the file must be created within the application directory. We can create the necessary file and open it in our text editor with root privileges by typing:

    sudo nano /usr/share/phpmyadmin/.htaccess
    

    Within this file, we need to enter the following information:

    AuthType Basic
    AuthName "Restricted Files"
    AuthUserFile /etc/phpmyadmin/.htpasswd
    Require valid-user
    

    Let’s go over what each of these lines mean:

    • AuthType Basic: This line specifies the authentication type that we are implementing. This type will implement password authentication using a password file.
    • AuthName: This sets the message for the authentication dialog box. You should keep this generic so that unauthorized users won’t gain any information about what is being protected.
    • AuthUserFile: This sets the location of the password file that will be used for authentication. This should be outside of the directories that are being served. We will create this file shortly.
    • Require valid-user: This specifies that only authenticated users should be given access to this resource. This is what actually stops unauthorized users from entering.

    When you are finished, save and close the file.

    Create the .htpasswd file for Authentication

    Now that we have specified a location for our password file through the use of the AuthUserFiledirective within our .htaccess file, we need to create this file.

    We actually need an additional package to complete this process. We can install it from our default repositories:

    sudo apt-get install apache2-utils
    

    Afterward, we will have the htpasswd utility available.

    The location that we selected for the password file was “/etc/phpmyadmin/.htpasswd“. Let’s create this file and pass it an initial user by typing:

    sudo htpasswd -c /etc/phpmyadmin/.htpasswd username
    

    You will be prompted to select and confirm a password for the user you are creating. Afterwards, the file is created with the hashed password that you entered.

    If you want to enter an additional user, you need to do so without the -c flag, like this:

    sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser
    

    Now, when you access your phpMyAdmin subdirectory, you will be prompted for the additional account name and password that you just configured:

    http://domain_name_or_IP/phpmyadmin
    

    phpMyAdmin apache password

    After entering the Apache authentication, you’ll be taken to the regular phpMyAdmin authentication page to enter your other credentials. This will add an additional layer of security since phpMyAdmin has suffered from vulnerabilities in the past.

    Conclusion

    You should now have phpMyAdmin configured and ready to use on your Ubuntu 14.04 server. Using this interface, you can easily create databases, users, tables, etc., and perform the usual operations like deleting and modifying structures and data.

    To learn how to further secure your interactions with the server by encrypting your communication with SSL, check out our article on setting up SSL certificates with phpMyAdmin.

    PhpMyAdmin Tutorial: Create Database

    In this part of our PhpMyAdmin tutorial we will describe the steps which must be followed in order to create a new database, add a table with records, create a database backup and perform a database restore procedure.

    We will start with the database creation.

    How to Create a MySQL Database?

    Please note that you can not create a database directly through cPanel->PhpMyAdmin due to the lack of user privileges. However, you can easily create a new database from your cPanel->MySQL Databases. Navigate to the Create New Database box. Enter the database name in the New Database text field and click on the Create Database button.

    The database name will be preceded by the cPanel username. For example, if your cPanel user name is user and you want to have a database named test, the actual database name will be user_test. You will get a confirmation message.

    How to Add MySQL Database Tables?

    Navigate to your cPanel->PhpMyAdmin tool and open the newly create database. It is empty and there are no tables.

    Enter the table name and the number of fields. Click on the Go button to create the table.

    On the next screen you should enter the fields’ names and the corresponding properties. The properties are:

    Type

    Here you should pick the type of the data, which will be stored in the corresponding field. More details about the possible choices can be found in the official MySQL Data Types documentation.

    Length/Values

    Here you should enter the length of the field.  If the field type is “enum” or “set”, enter the values using the following format: ‘a’,’b’,’c’…

    Collation

    Pick the data collation for each of the fields.

    Attributes

    The possible attributes’ choices are:

    BINARY – the collation for the field will be binary, for example utf8_bin;

    UNSIGNED –  the field numeric values will be positive or 0;

    UNSIGNED ZEROFILL – the field numeric values will be positive or 0 and leading zeros will be added to a number;

    ON UPDATE CURRENT_TIMESTAMP – the value for a data type field has the current timestamp as its default value, and is automatically updated;

    Null

    Here you define whether the field value can be NULL. More about the NULL value can be found in the corresponding MySQL documentation.

    Default

    This property allows you to set the default value for the field.

    Extra

    In the Extra property you can define whether the field value is auto-increment.

    The radio buttons that come below define whether there is an Index defined for the particular field and specify the Index type.

    Comments

    Here you can add comments, which will be included in the database sql code.

    At the end you can include Table comments and pick the MySQL Storage Engine and the Collation. Once you are ready, click on the Save button.

    If you want to add more fields you should specify their number and click on the Go button instead of Save.

    The database table will be created and you will see the corresponding MySQL query.

    Now we will proceed with the populating of the table with data.

    How to Add Content in a Database Table?

    In order to add records in a database table click on the Insert tab.

    Enter the data in the corresponding fields and click on the Go button to store it.

    At the bottom of the page you will see a drop-down menu labelled Restart insertion with x rows . There you can pick the number of the rows that you can populate with data and insert at once. By default the value is 2.

    The Ignore check box will allow you to ignore the data entered below it. It will not be added.

    You can see the newly inserted record by clicking on the Browse tab.

    You can edit or delete the record by clicking on the corresponding icons.

    To insert more records, return to the Insert tab and repeat the procedure.

    How to Backup a Database?

    Once you are ready, you can create a backup of your database through the Export tab.

    Select the tables which you want to be exported.

    Leave the radio button selection to the SQL option.  The Structure and the Data check boxes should remain checked.

    Select the Save as file check box and then click on the Go button.

    In this way you will save the dump SQL file with your database structure and content on your local computer.

    If you have a large database with a lot of records, the server timeout value can be reached. In such a case you can export the database in several batches. You can find more details in our MySQL Knowledge Base.

    How to Restore a Database Backup?

    You can restore your database backup from the Import tab.

    Click on the Browse button to select your database backup file from your local computer.

    Pick the charset of the file from the corresponding drop-down menu.

    If the file is too big, the MySQL server timeout can be reached. In such a case you can interrupt the import action. Then you can continue with the data import defining the number of the queries to be skipped from the file beginning. In this way you will skip the imported queries and continue from the point of the interruption.

  • Installing MySQL Server on Ubuntu

    Meet MySQL

    MySQL is an open-source relational database. In a nutshell, for those unfamiliar with it: A database is where an application keeps its stuff.

    To break it down a little further, “relational database” is a term that refers to how data is organized and accessed within the database. The “SQL” part refers to the language used by application queries to retrieve and store data (“Structured Query Language”).

    MySQL is free and widely used, meaning you can find a lot of application support, tools, and community help for it. MySQL is a safe choice if you know you need a database but don’t know what to make of the options that are out there.

    This article covers a basic installation of a MySQL server on Ubuntu Linux – just enough to get you started. Remember that you might need to install other packages to let apps use MySQL, like extensions for PHP. Check your application documentation for details.

    Installing MySQL

    The easiest way to install the MySQL server is through the Ubuntu package manager:

    sudo aptitude update
    sudo aptitude install mysql-server

    The installer should ask you to set a root password. It’s strongly advised you do so, but if you miss your chance during the install we’ll show you how to set the root password a little further on.

    iptables

    If you have iptables enabled and want to connect to MySQL from another machine you’ll need to open a port in your server’s firewall (the default port is 3306). You don’t need to do this if the application using MySQL is running on the same machine.

    If you do need to open a port (again, only if you’re accessing MySQL from a different machine from the one you’re installing on), you can use the following rules in iptables to open port 3306:

    -I INPUT -p tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
    -I OUTPUT -p tcp --sport 3306 -m state --state ESTABLISHED -j ACCEPT

    Launch MySQL

    Now that MySQL is installed you can make sure it’s running by trying to launch it:

    sudo service mysql start

    If you see a message that it’s already running that’s okay (it means that, well, it’s already running).

    Launching at boot

    This should also have been done for you at install time, but just in case:

    sudo /usr/sbin/update-rc.d mysql defaults

    That makes sure your machine will launch the MySQL server when it reboots.

    The MySQL shell

    There is more than one way to manage a MySQL server, so we’ll focus on the most basic and compatible approach: The mysql shell.

    At the command prompt, run:

    /usr/bin/mysql -u root -p

    That will attempt to launch the mysql client and enter the shell as user “root”. When you’re prompted for a password enter the one you set at install time or, if you haven’t set one, just hit enter to submit no password.

    You should be greeted by the mysql shell prompt:

    mysql>

    Setting the root password

    If you got in by entering a blank password, or want to change the root password you’ve set, you can do it by entering the following command in the mysql shell. Replace the “password” in quotes with your desired password:

    UPDATE mysql.user SET Password = PASSWORD('password') WHERE User = 'root';

    It’s kind of a mouthful. The reason for this is that MySQL keeps user data in its own database, so to change the password we have to run an SQL command to update the database.

    Next we’ll reload the stored user information to make our change go into effect:

    FLUSH PRIVILEGES;

    Note that we’re using all-caps for SQL commands. If you type those commands in lowercase they’ll work too. By convention the commands are written in all-caps to make them stand out from field names and other data that’s being manipulated.

    Looking at users

    As mentioned in the previous section, MySQL stores the user information in its own database. The name of the database is “mysql”. Inside that database the user information is in a “table”, a dataset, named “User”.

    If you want to see what users are set up in MySQL you need to run a query against the “user” table in the “mysql” database. Let’s do that now:

    SELECT User, Host, Password FROM mysql.user;

    Breaking that down…

    The “SELECT” command tells MySQL you’re asking for data.

    The “User, Host, Password” part tells MySQL what fields you want it to look in. Fields are categories for the data in a table. In this case we’re looking for the username, the host associated with the username, and the encrypted password entry.

    Finally, the “FROM mysql.user” part of the command tells MySQL to get the data from the “mysql” database and the “user” table.

    And then the command ends with a semicolon

    About that semicolon

    All SQL queries end with a semicolon. MySQL will wait for you to keep entering additions to a query until it sees a semicolon.

    That means that you can break lines up into smaller parts to make them easier to read. For example, the above command also works if you enter it in multiple lines in the mysql shell, as in:

    mysql> SELECT User, Host, Password
        -> FROM mysql.user;

    When you hit “enter” after the “Password” part you’ll get a new line so you can keep typing. The “->” indicates that the shell thinks you’re still in the middle of a statement. You can type a semicolon by itself to end the command if you simply forgot it on the first line.

    User hosts

    Okay, with that important aside about the semicolon done, let’s look at the output of that query:

    SELECT User, Host, Password FROM mysql.user;
    +------------------+-----------+-------------------------------------------+
    | User             | Host      | Password                                  |
    +------------------+-----------+-------------------------------------------+
    | root             | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    | root             | demohost  | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    | root             | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    | debian-sys-maint | localhost | *03C2F472E5290DDE27E889681C90EA91FD6800F3 |
    |                  | %         |                                           |
    +------------------+-----------+-------------------------------------------+

    As you can see, users are associated with a host – specifically, the host they connect to. The “root” user in this case is defined for localhost, for the IP address of localhost, and the hostname of the server (“demohost” in this example). You’ll usually only need to set a user for one host, the one you typically connect from.

    If you’re running your application on the same machine as the MySQL server the host it connects to by default will be “localhost”. That means any new users you create will need to have “localhost” in its “host” field.

    If your application connects remotely the “host” entry MySQL will look for is the IP address or DNS hostname of the remote machine (the one the client is coming from).

    A special value for the host is “%”, as you’ll see for the blank user (more on that shortly). That’s a wildcard that applies to any host value. You usually won’t want to use that because it’s more secure to limit access specifically to trusted hosts.

    Anonymous users

    In the example output above you’ll notice there’s one entry that has a host value but no username or password. That’s an “anonymous user”. When a client connects with no username specified it’s trying to connect as an anonymous user.

    You usually don’t want one of those in there, but some MySQL installations include one by default. If you see one of those you should either delete the user (refer to the username with empty quotes, like ”) or set a password for it (we cover both tasks later in this series).

    Create a database

    That covers some basic concepts surrounding users, so now let’s look at creating a database.

    It’s worth noting at this point that there is a difference between a “database server” and an actual “database”, even though you’ll often see those terms used interchangeably. MySQL itself is a database server, meaning that it keeps track of databases and controls access to them. An actual database is where all the data goes. That’s what applications are trying to get at when they talk to MySQL.

    Some applications will create a database as part of their setup process, while others require you to create a database yourself and tell the application about it later. Fortunately it’s an easy process.

    To create a database, log into the mysql shell and run:

    CREATE DATABASE demodb;

    That’s all there is to it. Replace “demodb” with the name of the database you want to create, of course. You can make sure it’s there by running a query to list all databases:

    SHOW DATABASES;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | demodb             |
    | mysql              |
    +--------------------+
    3 rows in set (0.00 sec)

    Add a database user

    It’s not a good idea to have applications connecting to the database using the root user. That gives them more privileges than they need. We’ll create a user named “demouser” that applications can use to connect to the new database.

    To make the user run the following in the mysql shell:

    INSERT INTO mysql.user (User,Host,Password) VALUES('demouser','localhost',PASSWORD('demopassword'));

    When you make changes to the user table in the mysql database you need to tell MySQL to read the changes by flushing the privileges. To wit:

    FLUSH PRIVILEGES;

    You can make sure the user is there by running that “select” query again:

    SELECT User, Host, Password FROM mysql.user;
    +------------------+-----------+-------------------------------------------+
    | User             | Host      | Password                                  |
    +------------------+-----------+-------------------------------------------+
    | root             | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    | root             | demohost  | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    | root             | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    | debian-sys-maint | localhost | *03C2F472E5290DDE27E889681C90EA91FD6800F3 |
    | demouser         | localhost | *0756A562377EDF6ED3AC45A00B356AAE6D3C6BB6 |
    +------------------+-----------+-------------------------------------------+

    Grant database user permissions

    Right now our new user has no privileges. It can be used to log on, but it can’t be used to make any database changes. Let’s give it full permissions for our new database by running:

    GRANT ALL PRIVILEGES ON demodb.* to demouser@localhost;

    And follow it up with the usual:

    FLUSH PRIVILEGES;

    To check those privileges were set, we’ll run:

    SHOW GRANTS FOR 'demouser'@'localhost';
    +-----------------------------------------------------------------------------------------------------------------+
    | Grants for demouser@localhost                                                                                   |
    +-----------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'demouser'@'localhost' IDENTIFIED BY PASSWORD '*0756A562377EDF6ED3AC45A00B356AAE6D3C6BB6' |
    | GRANT ALL PRIVILEGES ON `demodb`.* TO 'demouser'@'localhost'                                                    |
    +-----------------------------------------------------------------------------------------------------------------+
    2 rows in set (0.00 sec)

    What you get back are the commands needed to reproduce that user’s permissions if you were to rebuild the server. The “USAGE on *.*” part basically means they get no privileges on anything by default. Then that gets overridden by the second command, which is the grant you ran for the new database.

    Summary

    And that’s all you need if you’re just creating a database and a user. We were a bit long on concepts there but that should give you a solid grounding from which to learn more. Good work.

    Configuring MySQL server on Ubuntu

    Beyond the defaults

    In the previous article we covered a basic MySQL server setup on Ubuntu Linux. We set the root password, created a database, and created a user for the database. Now let’s look at MySQL in a little more detail so we can tweak its configuration and be ready in case something goes wrong.

    Finding the config files

    By default you’ll find MySQL’s configuration files in:

    /etc/mysql

    If they’re not there, however, you can ask mysqld where it looks for its config. Run the command:

    /usr/sbin/mysqld --help --verbose

    You’ll get a flood of text back. The first part describes the options you can send to the server when you launch it. The second part is all the configuration stuff that was set when the server was compiled.

    What we’re looking for shows up near the start of the output. Find a couple lines that look like:

    Default options are read from the following files in the given order:
    /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

    And there we are. The server works down that list until it finds a configuration file.

    my.cnf

    With the location in hand, open the my.cnf file and have a look inside.

    /etc/mysql/my.cnf

    Any lines starting with “#” are comments, and they mostly document what the different settings are for. They’re good to read through. You’ll find details like the location of log files and where the database files are kept.

    Config groups

    There are lines in the config file that just contain a word in square brackets, like “[client]” or “[mysqld]”. Those are “config groups” and they tell the programs that read the configuration file which parts they should pay attention to.

    See, while we’ve been focusing on the server part of MySQL, it’s technically a collection of tools. That includes the server (mysqld), the client (mysql), and some other tools we’ll talk about in a bit. Those programs look in my.cnf to see how they should behave.

    There’s a bit more to it, but basically: The “client” config section controls the mysql client, and the “mysqld” section controls the server config.

    Log files

    If something does go wrong the best place to start troubleshooting any program is its logs. By default MySQL stores its log files in the directory:

    /var/log/mysql

    You may need to use sudo to get a listing of the files in that directory.

    If you don’t find the MySQL logs in the default directory you’ll need to check MySQL’s config. Look in the my.cnf file and look for a “log_error” line, as in:

    log_error = /var/log/mysql/error.log

    If you don’t see a line like that, create one in the “mysqld” section so MySQL will use its own error log. We recommend using the location in the example, creating the “/var/log/mysql” directory if it doesn’t already exist. Then restart MySQL to make the change.

    Make sure the log directory you choose can be written to by the user controlling the MySQL process (usually “mysql”). The user running the process will be defined in the “user” config value for mysqld in my.cnf.

    Network settings

    There might be a “port” setting under both the client and server config sections. The port under the server section controls what port the server will listen to. By default that’s 3306 but you can change it to anything you’d like.

    The port in the client section tells the client what port to connect to by default. You’ll generally want the two port settings to match up.

    If you don’t see the port entries in the config file that just means they’re using the default. If you want to change the port you would add the lines in the appropriate categories:

    [client]
    port = 3306
     
    [mysqld]
    port = 3306

    The other network setting to look for is the “bind-address” value. That usually gets set to the address for localhost, 127.0.0.1. By binding to localhost the server makes sure no one can connect to it from outside the local machine.

    If you’re running your MySQL server on a different machine from your application you’ll want to bind to a remotely-accessible address instead of localhost. Change the bind-address setting to match your public IP address (or, better, a backend IP address on a network that fewer machines can access).

    If you don’t see a “bind-address” entry you should put one into the “mysqld” category to help control access to the server:

    [mysqld]
    bind-address = 127.0.0.1

    Remember to account for the client’s hostname when you set up your database users and to poke a hole in your firewall if you’re running iptables.

    mysqld and mysqld_safe

    Behind the scenes there are actually two versions of the MySQL server, “mysqld” and “mysqld_safe”. Both read the same config sections. The main difference is that mysqld_safe launches with a few more safety features enabled to make it easier to recover from a crash or other problem.

    Both mysqld and mysqld_safe will read config entries in the “mysqld” section. If you include a “mysqld_safe” section, then only mysqld_safe will read those values in.

    By default the mysql service launches “mysqld_safe”. That’s a good thing, and you should only look to change that if you really know what you’re doing.

    mysqladmin

    The mysqladmin tool lets you perform some administrative functions from the command line. We won’t talk much about it here because we’re just trying to get you up and running with enough basics to get by. It’s worth looking at the tool in more depth later to see what it can do, particularly if you need to build scripts that perform functions like checking the status of the server or creating and dropping databases.

    Backups

    You have a few options when it comes to making backups of your databases apart from the usual “back up the whole machine” approach. The main two are copying the database files and using mysqldump.

    File copy

    By default MySQL creates a directory for each database in its data directory:

    /var/lib/mysql

    Once you’ve found the data directory, hold off a moment before making a copy of it. When the database server is active it could be writing new values to tables at any time. That means if it writes to a table halfway through your copy some files will change and lead to a corrupt backup. Not a good thing if you’re trying to plan for disaster recovery.

    To make sure the database files are copied cleanly you can shut the MySQL server down entirely before the copy. That’s safe but isn’t always ideal.

    Another approach you can take is to lock the database as read-only for the duration of the copy. Then when you’re done, release the lock. That way your applications can still read data while you’re backing up files.

    Lock the databases to read-only by running, from the command line:

    mysql -u root -p -e "FLUSH TABLES WITH READ LOCK;"

    To unlock the database when you’re done, run:

    mysql -u root -p -e "UNLOCK TABLES;"

    We’re using a new option with the mysql client, “-e”. That tells the client to run the query in quotes as if we’d entered it in the mysql shell proper.

    Note that if you’re setting these commands up in a script you can put the password in quotes right after “-p” with no space between the two, as in:

    mysql -u root -p"password" -e "FLUSH TABLES WITH READ LOCK;"
    mysql -u root -p"password" -e "UNLOCK TABLES;"

    Just make sure you set the permissions on that file to restrict read access. We don’t want just anyone to be able to see that password.

    mysqldump

    Another approach to backing up your database is to use the “mysqldump” tool. Rather than copying the database files directly, mysqldump generates a text file that represents the database. By default the text file contains a list of SQL statements you would use to recreate the database, but you can also export the database in another format like CSV or XML. You can read the man page for mysqldump to see all its options.

    The statements generated by mysqldump go straight to standard output. You’ll want to specify a file to redirect the output to when you run it. For example:

    mysqldump -u root -p demodb > dbbackup.sql

    That command will tell mysqldump to recreate the “demodb” database in SQL statements and to write them to the file “dbbackup.sql”. Note that the username and password options function the same as the mysql client, so you can include the password directly after “-p” in a script.

    Restore from mysqldump

    Restoring a mysqldumped database looks similar to what was used to create it, but we use plain old “mysql” instead of “mysqldump”:

    mysql -u root -p demodb < dbbackup.sql

    We also change from a greater-than to a less-than sign. That switches the command from redirecting its output to telling it to read its input from the existing file. That input is sent to the “mysql” command, causing the mysqldumped instructions to recreate the database.

    Note that by default the SQL statements generated would just add to existing database tables, not overwrite them. If you’re restoring a backup over an existing database you should drop the database’s tables first, or drop and recreate the database itself. You can change that behavior by using the “–add-drop-table” option with the command that creates the mysqldump. That causes mysqldump to add a command to the backup files it writes that will drop tables before recreating them.

    Database engine

    The last concept we’ll talk about here is that of the “database engine”. The engine is the process that’s churning away behind the scenes, writing to and reading data from files. You won’t usually need to know anything other than that it’s there, but sometimes you’ll want to run an application that’s been optimized for a particular database engine.

    The engine type is set when a table is created. Tables are usually created by the application that’s going to use them, which is why we aren’t going to get into that syntax here.

    To see the engine used by your database’s tables you can run the following command in the MySQL shell:

    SHOW TABLE STATUS FROM demodb;

    Change “demodb” to the name of your database.

    Choosing an engine

    Ideally you won’t need to choose an engine. If you’re not very familiar with MySQL that’s certainly the safest way to go – let the application do its thing, and if you’re writing the application, use the default engine until you’re more comfortable with your options.

    If you have a database administrator, do whatever he or she says. They’re smart people, they know what they’re talking about.

    The two database engines used most often with MySQL are “MyISAM” and “InnoDB”. The default database engine for MySQL version 5.1 and earlier is MyISAM, while InnoDB is the default database engine starting with MySQL version 5.5.

    MyISAM

    Because MyISAM has been the default in MySQL for a while it’s the most compatible choice of the two main engines. Certain types of searches perform better on MyISAM than InnoDB. Just because it’s the older of the two doesn’t mean it can’t be the best for a given application type.

    InnoDB

    InnoDB is more fault-tolerant than MyISAM and handles crashes and recovery with a much smaller chance of database corruption. This is a good thing.

    The main trouble with InnoDB is that for best performance it requires a lot of tweaking for your environment and access patterns. If you have a DBA that’s no problem, but if you’re a developer who just wants a database up and running for a test server you probably won’t want to deal with tuning InnoDB.

    It’s possible you may be running an application that requires InnoDB, and if you’re using MySQL 5.1 or earlier there might not be any settings already in the my.cnf config file. That can be a problem if you’re running on a server that doesn’t have an abundance of memory.

    Some settings to get you started with InnoDB on a shared server with 256 megs of RAM are:

    innodb_buffer_pool_size = 32M
    innodb_log_file_size = 8M
    innodb_thread_concurrency = 8
    innodb_file_per_table

    Add those to the [mysqld] section of the config file. Again, those are only rough guides – enough to get you running, but definitely not optimized. For that you’ll probably want a DBA, or at least to experiment with incremental changes over time.

    Summary

    Now you should have MySQL configured for your environment, and might even have accounted for the database engine being used by your tables.

  • How To Install KVM On Ubuntu And Run Virtual Machines

    How To Install KVM On Ubuntu And Run Virtual Machines

    Kernel Virtual Machine (KVM) is one of the popular virtualization solutions available today to run guest  Operating Systems (Virtual Machines) on a Linux hosts (Physical Machines). Few other popular alternatives are Oracle VirtualBox, VMware Player / Workstation and Xen. In this article, we will focus on installing KVM on Ubuntu and running a guest Virtual Machine.

    Recommended Prerequisites

    You will need a processor that supports hardware virtualization. To see if your processor supports it, run “egrep -c ‘(vmx|svm)’ /proc/cpuinfo“. If the output is greater than 0 then your all set. But you still need to check if the feature has been enable in your  BIOS, to check run “kvm-ok“. This should generate the following output,

    output-1

    Note: To run “kvm-ok” command you will need the “cpu-checker” package installed. To install, simply run the command “sudo apt-get install cpu-checker“.

    It is also recommended to run a 64 bit host operating system, but not required. First, to check if you have a 64 bit processor, run “egrep -c ‘ lm ‘ /proc/cpuinfo“. Again, if the output is greater than 0, then you should be good. Next, to check if your OS is running a 64 bit kernel, run command “uname -m“. This should generate the below output,

    output-2

    KVM Installation

    Once you have sufficed the pre-requisites, to install KVM on Ubuntu and run guest Virtual Machines, simply run the command “sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils“. This will install the related software packages. Also optionally, to manage Virtual Machines using a GUI front-end, install the “virt-manager” package by running the command “sudo apt-get install virt-manager“. Once done, reboot the machine and you should be ready to use KVM. To verify if your  installation was successful, run “virsh -c qemu:///system list” or alternatively launch the Virtual Machine Manager application. The earlier command should generate the below output if the install was a success.

    output-3

    Creating & Running a Virtual Machine

    Now that we are done installing KVM and related packages we can create and run Virtual Machines. To get started, lets create a Virtual Machine as an example. Launch the Virtual Machine Manager and click on the “Create a new virtual machine” icon in the top left. (See below screen shot)

    kvm-1This brings up the “New VM” wizard. Follow the wizard as shown in the screen shots below to create a new Virtual Machine.

    kvm-2

    kvm-3kvm-4kvm-5kvm-6Lastly, click “Finish” to begin guest operating system installation on the new Virtual Machine. If you have tried or use other similar virtualization products, let me know how you like KVM in contrast.

  • How to Install KVM and Create Virtual Machines on Ubuntu

    If you’re using Linux, you don’t need VirtualBox or VMware to create virtual machines. You can use KVM – the kernel-based virtual machine – to run both Windows and Linux in virtual machines.

    You can use KVM directly or with other command-line tools, but the graphical Virtual Machine Manager (Virt-Manager) application will feel most familiar to people that have used other virtual machine programs.

    Installing KVM

    KVM only works if your CPU has hardware virtualization support – either Intel VT-x or AMD-V. To determine whether your CPU includes these features, run the following command:

    egrep -c ‘(svm|vmx)’ /proc/cpuinfo

    A 0 indicates that your CPU doesn’t support hardware virtualization, while a 1 or more indicates that it does. You may still have to enable hardware virtualization support in your computer’s BIOS, even if this command returns a 1 or more.

    image

    Use the following command to install KVM and supporting packages. Virt-Manager is a graphical application for managing your virtual machines — you can use the kvm command directly, but libvirt and Virt-Manager simplify the process.

    sudo apt-get install qemu-kvm libvirt-bin bridge-utils virt-manager

    Only the root user and users in the libvirtd group have permission to use KVM virtual machines. Run the following command to add your user account to the libvirtd group:

    sudo adduser name libvirtd

    image

    After running this command, log out and log back in. Run this command after logging back in and you should see an empty list of virtual machines. This indicates that everything is working correctly.

    virsh -c qemu:///system list

    image

    Creating Virtual Machines

    Once you’ve got KVM installed, the easiest way to use it is with the Virtual Machine Manager application. You’ll find it in your Dash.

    image

    Click the Create New Virtual Machine button on the toolbar and the Virtual Machine Manager will walk you through selecting an installation method, configuring your virtual machine’s virtual hardware, and installing your guest operating system of choice.

    image

    The process will by familiar if you’ve ever used VirtualBox, VMware, or another virtual machine application. You can install from a disc, ISO image, or even a network location.

    image

    To assign more than 2GB of memory to a virtual machine, you’ll need a 64-bit Linux kernel. Systems running 32-bit kernels can assign a maximum of 2 GB of RAM to a virtual machine.

    image

    By default, KVM gives you NAT-like bridged networking – your virtual machine won’t appear on the network as its own device, but it will have network access through the host operating system. If you’re running server software in your virtual machine and want it accessible from other devices on the network, you’ll have to tweak the networking settings.

    image

    After selecting your installation method, Virt-Manager will boot the guest operating system in a window. Install the guest operating system as you would on a physical machine.

    image

    Managing Virtual Machines

    The Virtual Machine Manager window displays a list of your installed virtual machines. Right-click virtual machines in the window to perform actions, including starting, shutting down, cloning, or migrating them.

    image

    You can view information about the virtual machine and configure its virtual hardware by clicking the i-shaped toolbar icon in the virtual machine’s window.

    image

    What is JeOS? (Minimal Ubuntu’s OS install)

    JeOS (just enough operating system) is a highly customized operating system built for a specific application. The acronym is pronounced “juice.”

    JeOS builds are popular with software vendors and developers who are creating test systems or virtual appliances.  A virtual appliance is simply a virtual machine (VM) image file that has a preconfigured operating system (OS) and a single application. (The preconfigured OS is the JeOS.)

    A JeOS only includes the bits of a full-blown operating system that are required to support the application and any other third-party components that are packaged in the appliance.  Configuring the JeOS and the application together in a single package helps avoid installation issues and errors.