Category: Linux Toggle Comment Threads | Keyboard Shortcuts

Over 80% is running on some form of Linux – so does your Mac and you iPhone. Sometimes we have to get our hands dirty on the command line – it makes you feel like a proper hacker.

Here are some pointers I picked up on my journey.

  • Jay Versluis 12:36 am on March 25, 2015 Permalink | Reply  
    Categories: Linux ( 63 )

    How to find the UUID of a disk drive in Linux 

    There are two ways I know of which will print the UUID of all disk drives attached to the current system:

    blkid
    
    /dev/sr0: UUID="2014-12-02-19-30-23-00" LABEL="CDROM" TYPE="iso9660" 
    /dev/sda1: UUID="ae55a647-3c57-4ab5-9651-1389703fe6fe" TYPE="ext4" 
    /dev/sda2: UUID="bMtCfO-zpDU-7U1t-DcHg-Fe9p-Cy1K-Se0e1I" TYPE="LVM2_member" 
    /dev/sdb1: UUID="0982ce66-537a-497b-baaf-99136594f3e8" TYPE="ext4" 
    /dev/mapper/VolGroup-lv_swap: UUID="8f0652a8-d79b-453f-aa2d-0ff0b5d0ae7b" TYPE="swap" 
    /dev/mapper/VolGroup-lv_root: UUID="5afc1b25-e6cd-45b2-ad20-69f0fed323b9" TYPE="ext4" 
    /dev/mapper/VolGroup-lv_home: UUID="94e15e98-1cff-49a9-b76a-a8f3a948e2ea" TYPE="ext4" 
    

    or

    ls -la /dev/disk/by-uuid
    
    total 0
    drwxr-xr-x. 2 root root 160 Mar 25 00:24 .
    drwxr-xr-x. 5 root root 100 Mar 25 00:24 ..
    lrwxrwxrwx. 1 root root  10 Mar 25 00:24 0982ce66-537a-497b-baaf-99136594f3e8 -> ../../sdb1
    lrwxrwxrwx. 1 root root   9 Mar 25 00:24 2014-12-02-19-30-23-00 -> ../../sr0
    lrwxrwxrwx. 1 root root  10 Mar 25 00:24 5afc1b25-e6cd-45b2-ad20-69f0fed323b9 -> ../../dm-1
    lrwxrwxrwx. 1 root root  10 Mar 25 00:24 8f0652a8-d79b-453f-aa2d-0ff0b5d0ae7b -> ../../dm-0
    lrwxrwxrwx. 1 root root  10 Mar 25 00:24 94e15e98-1cff-49a9-b76a-a8f3a948e2ea -> ../../dm-2
    lrwxrwxrwx. 1 root root  10 Mar 25 00:24 ae55a647-3c57-4ab5-9651-1389703fe6fe -> ../../sda1
    

    The UUID is required to permanently mount specific disk drives in /etc/fstab.





     
  • Jay Versluis 8:45 am on March 7, 2015 Permalink | Reply
    Tags: ,   

    Categories: Linux ( 63 )

    How to specify FTP credentials in command line scripts 

    It’s easy to establish an FTP connection using the ftp command from the Linux Command Line. Sadly this command does not accept login credentials as parameters – which means that if we use it in a script, our script will pause and wait for us to type those credentials in manually. Not really suitable for automated backups.

    Thanks to a clever mechanism called netrc we can create a file in the home directory of the user who runs the script and provide credentials there. Let me show you how this works.

    First we create a file called .netrc. It’s a hidden file and it needs to reside in the home directory of the user who will connect via FTP. I’m going to use root for this:

    vi ~/.netrc
    
    # machine  login  password 
    machine ftp.domain.com login yourusername password yourpassword
    

    The first line is just a comment to you can remember how to add parameters here. The second line is an example of a host you want to connect to. Add as many other servers as you like, all following the same pattern.

    Be aware that you need to connect to the server as it is specified in the .netrc file. In the above example, if you would connect to domain.com instead, you would be asked for credentials as netrc cannot find a match.

    The .netrc file needs to be readable only by this one user, otherwise connections may fail. We do this by changing the file permissions to 600:

    chmod 600 ~/.netrc
    

    That should do it! Try to connect with

    ftp ftp.domain.com
    

    and the connection will be established without the prompt for credentials.

    If netrc isn’t working for you, or you choose not to use it, note that you can also provide FTP credentials with a here script. I find that approach a bit clunky, but the following link has details on how to do that:





     
  • Jay Versluis 7:48 pm on March 5, 2015 Permalink | Reply
    Tags: , Jekyll   

    Categories: Linux ( 63 )

    Getting started with Jekyll on CentOS 7 

    jekyll-iconIt’s not quite as easy to get up and running with Jekyll as the Quick Start Guide makes it sound. But it’s not super difficult either – if explained from one human to another.

    Here’s how I got Jekyll working on a vanilla CentOS 7 instance.

    Installing some necessary packages

    Before we can install Jekyll using Rubygems, we need a few packages which aren’t with us by default. One comes from the Fedora EPEL repository, so let’s enable that first:

    yum install epel-release
    

    I love how easy this has become since CentOS 7! Next, some packages. We’ll need Ruby and the developer extensions. We also need a web server, so I’ll choose Apache – but I understand that others work just as well.

    The installation guide doesn’t mention it, but it is actually mandatory to have a JavaScript runtime present, as mentioned in this project (which I guess Jekyll relies upon): https://github.com/sstephenson/execjs. Let’s choose NodeJS as its available from EPEL.

    What this boils down to are the following packages:

    yum install ruby ruby-devel nodejs httpd
    

    Great! Now that Ruby is working, let’s install Jekyll via Rubygems:

    gem install jekyll
    

    This could take a moment, be patient. When it’s finished, let’s put Jekyll to work.

    Creating and previewing a test site

    Let’s call our new test site “test”. I’m assuming you’re in your home directory from which usually no web files shall ever be served – but thanks to Jekyll we can make that happen for local testing purposes. The following command will create a brand new site in the current directory:

    jekyll new test
    
    New jekyll site installed in /root/test.
    

    Excellent! But how do we get to see it? Well Jekyll has created a directory called “test” for us. Let’s enter it and preview the site:

    cd test
    jekyll serve
    
    Configuration file: /root/test/_config.yml
    Source: /root/test
    Destination: /root/test/_site
    Generating…
    done.
    Auto-regeneration: enabled for ‘/root/test’
    Configuration file: /root/test/_config.yml
    Server address: http://127.0.0.1:4000/
    Server running… press ctrl-c to stop.
    

    What Jekyll is trying to say is that IF we are building this on a system with a desktop environment, we could open a web browser and enter http://localhost:4000 now to preview the site. Jekyll spawns a web server on port 4000 so that we can see any changes we’ve made since last time without affecting a live site.

    Sadly this approach doesn’t work on remote servers though, at least not for me: port 4000 on a remote server simply did not respond. Regardless, on the local sever it was working just fine, and we should see a picture like this:

    Screen Shot 2015-03-05 at 19.40.06

    That’s a good start – let’s put the site live so that our web server can show it to the world!

    Building the site

    Press CTRL-C to stop the preview serving procedure and ask Jekyll to create this site in our default web directory. In CentOS that’s /var/www/html. Mine is empty so I’ll create the site there using

    jekyll build --destination /var/www/html
    
    Configuration file: /root/test/_config.yml
    Source: /root/test
    Destination: /var/www/html
    Generating…
    done.
    Auto-regeneration: disabled. Use –watch to enable.
    

    Nicely done! Now let’s surf to http://localhost (without the 4000 at the end), and the local machine should see this content served up fresh just like any other website. Remote computers should use either the IP address or a domain resolving to it (say http://12.34.56.78).

    Now that you know how it works, enjoy using Jekyll!





     
  • Jay Versluis 11:48 am on March 5, 2015 Permalink | Reply
    Tags: Android, Nook   

    Categories: Linux ( 63 )

    How to mount EXT4 partitions on Android Jelly Bean 

    Jelly-Bean-LogoI was racking my brains over how to mount an SD card formatted with anything other than FAT32 on my Android device. Jelly Bean and Kit Kat automatically mount FAT32 partitions, but they seem to ignore native Linux file systems – which Android clearly understands.

    Apparently there’s a $1.54 app on the Play Store that can auto-mount cards (called EzyMount), but there is a way to do this for free: namely the old fashioned manual way.

    All we need is root access to the device and a Terminal Emulator (available from the Play Store).

    In this example I’m using /sdcard as my mount point, but you can of course mount that card anywhere you like. On my Nook Tablet, the standard mount point for the SD card is /storage/sdcard1, but this differs from device to device of course.

    To mount the card, we’ll use the mount command:

    mount -t ext4 /dev/block/mmcblk1p1 /sdcard
    

    We need to specify the partition format with -t (for example, ext4, ext3, ext2), followed by the partition we want to mount, followed by the mount point. On my Nook Tablet for example, the SD card device itself is /dev/block/mmcblk1, and the first partition in it is mmcblk1p1.

    To figure out what a device is called can use

    ls /dev/block
    

    Run this command before and after inserting your storage device. Watch what changes: the added device will be your SD card or USB stick.

    Why do you need EXT4? Why not just use FAT32?

    I need my files to be larger than the 4GB maximum file size imposed by FAT32. I’m using Anton Skshidlevsky’s amazing Linux Deploy to install fully fledged versions of various Linux distributions on my device. These don’t replace Android, but instead run side by side with Android in a chrooted environment.

    Linux Deploy creates ISO images on the SD card which represent a full Linux installation (for example, Debian, Fedora, Ubuntu – anything that runs on your architecture). To be able to use the full size of an SD card, and to make the self-contained file system access more data, those ISO files can be as large as the SD card – even larger: Linux Deploy uses self-expanding ISO images, but you can only define partition sizes larger than 4GB if you have an EXT type file system on the card.

    In a nutshell: Bigger is better.





     
  • Jay Versluis 11:11 am on March 3, 2015 Permalink | Reply
    Tags: , Debian, Fedora, Ubuntu   

    Categories: Linux ( 63 )

    The Debian Experience: Cheat Sheet for CentOS and Fedora users 

    DebianI’ve just installed a LAMP stack on my Nook Tablet using Debian. However I’ve been using CentOS since 2008 and I’m so used to how things are done there that it was a bit of a culture shock doing relatively simple things “on the other side”. It’s like a country whose language you don’t speak well enough.

    Here are a few pointers for how to so these simple things in Debian and Ubuntu, for CentOS and Fedora Users:

    Installing Packages

    While I’m used to yum and it’s super easy search and install options, its counterpart apt is very different. Searching for packages is done with

    apt-cache search package

    instead of yum list. Likewise, installing a package is done with

    apt-get install package

    I believe the cache is not created automatically, so from time to time (or before an update/install operation) we need to run

    apt-get update

    To update all packages (equivalent to yum update), we have to run

    apt-get upgrade

    There are other front ends available which I have not explored yet. aptitude is for the command line and appears to have a similar simplified syntax to yum. synaptic is for GNOME like environments.

     

    LAMP Stack

    Apache is called httpd on CentOS, but it’s called apache2 on Debian. Its system user does not run as apache:apache, but as www-data:www-data.

    The web root directory is not in /var/www/html but instead in /var/www. File ownership should be tweaked to the above user in this directory. SELinux is not enabled by default.

    The Apache config file is not in /etc/httpd/httpd.conf but in /etc/apache2/apache2.conf. The content however is the same, except for the system user which is defined in envvars in the same directory.

    PHP is not just called php, but instead it’s php5 on Debian. This is true for all derivatives, such as

    • php5
    • php5-cli
    • php5-mysql
    • php5-gd

    MySQL is still MySQL in Debian Wheezy, and not MariaDB (yet).

     

    Starting and stopping services on boot

    chkconfig does not work on Debian. Instead we can use a script called update-rc.d. Here’s how to enable something at boot:

    update-rc.d apache2 defaults

    And to disable something:

    update-rc.d -f apache2 remove




     
  • Jay Versluis 7:23 pm on February 25, 2015 Permalink | Reply  
    Categories: Linux, Mac OS X, Windows ( 63 )

    How to find your CPU details from the command line 

    It’s often necessary to know what the exact type of CPU that’s installed on your system. For example, you may need to know if you’re dealing with a dual core or quad core system, or a 32/64 bit system. Only the CPU can tell you this.

    Here’s how to find out the string you need for further investigation.

     

    Windows

    From the command line, execute the wmic command with the following parameters:

    wmic cpu get name
    
    Name
    Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
    

    Thanks to Jonathan @ Next of Windows for this tip!

    Windows also gives you an accurate result via the GUI: open Windows Explorer and head over to Computer – Properties:

    Screen Shot 2015-02-25 at 19.04.01

    Mac OS X

    On the Mac you won’t get a very accurate result from the Apple Icon – About this Mac. It will tell you what CPU type you’re using, but not the exact model number.

    To find that out, head over to Applications – Utilities – Terminal and enter the following command:

    sysctl -n machdep.cpu.brand_string
    
    Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
    

    There. Much better than this:

    Screen Shot 2015-02-25 at 19.15.09

    Linux

    You can take a look at the /proc/cpuinfo file which holds a plethora of information about your system’s CPU. So much in fact that it’s difficult to find what you’re looking for. Filtering the output of this file for ‘model name’ gives you an exact match:

    cat /proc/cpuinfo | grep ‘model name’
    
    model name : Intel(R) Atom(TM) CPU N270   @ 1.60GHz
    

     

    Where can I find more information about my CPU?

    Google is of course your friend when trying to find out more information about your processor, but there are two tools provided by Intel and AMD that may also be of help. Intel’s ARK website is particularly helpful:





     
  • Jay Versluis 3:57 pm on February 23, 2015 Permalink | Reply
    Tags: ,   

    Categories: Linux ( 63 )

    How to find which package provides a command in yum 

    CentOS-LogoSometimes you know you need a package, but when you try to install it with yum you’ll get a message like “No matches found”. Yet you’re sure the package exists because you’ve used it before.

    This can happen if the package in question is part of a set which installs multiple packages. The net-tools package springs to mind.

    yum has a great option called whatprovides with which you can query what package you need to install to use a command. Let’s try it out!

    Say I wanted to install mkfs.vfat which is not installed by default in CentOS. Simply trying to install it won’t work:

    yum install mkfs.vfat
    
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.advancedhosters.com
     * extras: centos.mirrors.tds.net
     * updates: centos.mirrors.tds.net
    No package mkfs.vfat available.
    Error: Nothing to do
    

    Of course it won’t. But I can ask yum what provides this package:

    yum whatprovides mkfs.vfat
    
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.advancedhosters.com
     * extras: ftp.usf.edu
     * updates: centos.mirrors.tds.net
    dosfstools-3.0.20-9.el7.x86_64 : Utilities for making and checking MS-DOS FAT
                                   : filesystems on Linux
    Repo        : base
    Matched from:
    Filename    : /usr/sbin/mkfs.vfat
    
    
    
    dosfstools-3.0.20-9.el7.x86_64 : Utilities for making and checking MS-DOS FAT
                                   : filesystems on Linux
    Repo        : @base
    Matched from:
    Filename    : /usr/sbin/mkfs.vfat
    

    Well fantastic! The package I’m looking for is called dosfstools. Knowing that, I can simply use yum install dosfstools, and a few moments later mkfs.vfat will work as expected.

    Thanks, yum!





     
  • Jay Versluis 10:17 am on February 17, 2015 Permalink | Reply
    Tags: , squid   

    Categories: Linux ( 63 )

    How to view local websites on your iPad with Squid 

    squidI like developing and testing websites on my local network before they go live. On both Mac and PC it’s easy to tweak the /etc/hosts file so that the URL doesn’t point to a numeric IP, but instead to http://yourserver (or something equally catchy).

    On iOS devices we can’t tweak that file unless we deal with the highly unethical practice of jailbreaking. Turns out there is an easier way to surf local websites on mobile devices, simply by using a Proxy Server such as Squid.

    A Proxy Server is often used as a caching server or to disguise where a request is coming from. For example, surfers use proxies to pretend they’re visiting from a different country, or ISPs  use proxies to speed up data delivery in local areas. In simple terms, a proxy is fetching data on our behalf. Then we talk to the proxy and get the data from him. Think of a Proxy Server as a middle man in a network transaction.

    To surf local websites on an iPad or iPhone, we can connect to our WiFi network with a proxy on a machine on which we CAN tweak the /etc/hosts file. Let me show you how this works.

    For this example I’m using a development server on my local network. It’s a simple LAMP Stack running CentOS.

     

    Installing and configuring Squid

    We’ll install Squid on the development server. Websites are accessible via http://localhost but also as something more swish when the /etc/hosts file is tweaked, for example http://yourserver.

    Squid is available via yum, and installation is simple:

    yum install squid
    
    chkconfig squid on
    

    The second line will start Squid on every server restart, just in case.

    Squid should work out of the box on port 3128, but if you ever need to tweak this, you can do so in /etc/squid/squid.conf.

     

    Configuring the iPad Connection

    When you connect your iOS device to your local WiFi network it will do this without a Proxy Server by default. We’ll change this under Settings – WiFi, then tap the little info icon next to your active connection. It goes without saying that the development server needs to be on the same network as your iPad.

    At the bottom of this page, under “http proxy”, select manual and add your development/proxy server’s numeric IP, and 3128 under Port. Leave authentication off. It should look like this:

    image-2

     

    Now any tweaked URL that works on your development server will work on the iOS Device too: visit http://yourserver to verify this.

    Should Safari give you a problem, maybe due to its spurious caching technology, head over to Settings – Safari – Clear History and Website Data.

     

    Notes

    Squid will cache every request you make on your iOS device as long as your WiFi connection uses the proxy setting. Chances are that your development server isn’t going to deliver results as fast as non-cahced results would come in from your router – unless you surf the same slow website over and over.

    Also, Squid will leave a record of every request that has been made in /var/log/squid/access.log. If you’re using such a setup in your office, you may need to tell users on the network that their requests will be logged.

    So if you’re concerned about any of these aspects, simply switch the proxy off in your WiFi settings.

     





     
  • Jay Versluis 10:06 am on February 15, 2015 Permalink | Reply
    Tags: ,   

    Categories: Linux ( 63 )

    How to enable automatic logins in CentOS and GNOME 

    CentOS-LogoI was researching auto login options for CentOS today. I thought those would come in handy when GNOME is used as a standard desktop, so that the computer starts straight into the desktop environment without the need to provide a password.

    It’s also a handy feature to have if the machine lives in another room and needs GNOME to login to the wireless network when I issue a remote restart.

    Turns out there are two parts to the puzzle: providing auto logins and removing a pesky Keyring Dialogue that appears to come up when those are enabled. Let’s tackle both of them here.

    I’m using CentOS 6.6 with GNOME here, but the same principle also works in CentOS 7.

    Enabling Auto Logins

    Head over to the trusty command line and edit /etc/gdm/custom.conf. The file already contains several sections, all of which are empty by default.

    In the daemon section, add the following values (replacing youruser with your actual user name):

    # GDM configuration storage
    
    [daemon]
    AutomaticLoginEnable = true
    AutomaticLogin = youruser
    
    [security]
    
    [xdmcp]
    
    [greeter]
    
    [chooser]
    
    [debug]
    

    Thanks to Keith Wright on the CentOS Forum for this tip.

    Now when you restart your system, youruser is automatically logged in when GNOME starts.

    Disabling the Keyring Dialogue

    However, you may experience a Keyring Dialogue which will ask for your root password every time after a restart. This isn’t much better than the login screen. This may or may not happen, depending on your current configuration:

    Photo Feb 15, 8 47 34 AM

    One article I found suggested to head over to System – Preferences – Startup Applications and simply remove the Keyring Daemon from the list. Turns out this doesn’t actually make a difference, so don’t do that (although it doesn’t seem to have an adverse effect either):

    Remove-Keyring

    The real solution comes courtesy of Jim and iiSeymour: http://superuser.com/questions/43132/why-do-i-need-to-enter-a-password-for-the-default-keyring-to-unlock

    All we have to do is

    – head over to the Network Connections Icon at the top of the screen
    – and right-click it
    – select Edit Connections…
    – pick your current wireless connection and select Edit
    – provide the root password (only necessary this once)
    – check the tick box Available to all users

    Photo Feb 15, 8 59 55 AM

    Photo Feb 15, 9 00 10 AM

    Photo Feb 15, 9 00 30 AM

    In CentOS 7, choose the little gear icon to bring up a window. You can find the available to all users tick box in the Identity section on the left hand side.

    And that’s it! On subsequent logins, GNOME will now start with youruser already logged in and your wireless network connected.

    Wait! My system boots into the Command Line interface, even though I have GNOME installed. What gives?

    You can tell your system in which mode to start. To do this, edit your /etc/inittab file:

    // change this line 
    id:3:initdefault:
    
    // to 
    id:5:initdefault:
    




     
  • Jay Versluis 10:54 pm on February 10, 2015 Permalink | Reply
    Tags: , firewalld,   

    Categories: Linux ( 63 )

    How to set firewall rules from a GUI in CentOS 

    CentOS-LogoSick and tired of countless command line statements to set your firewall rules? Me too. No matter what I try, I never get the results quite right. There’s always some switch I forget and ultimately something isn’t working.

    For years I was thinking, “there has to be an easier way, like there is in Plesk”?

    And today I found that there is: a rather un-obvious tool called system-config-firewall. It’s a godsend and works in CentOS 6 with iptables, and in CentOS 7 with firewalld.

    Installation

    To make use of it, install the following two packages:

    yum install system-config-firewall system-config-firewall-tui
    

    The first one is a version that runs under Gnome and KDE, and second one works on the command line.

    The Command Line Version

    You can invoke the command line version by running

    sudo system-firewall-config-tui

    and it will present you with the following interface. You may need to switch the firewall off temporarily, but the tool will tell you if that’s necessary:

    Screen Shot 2015-02-10 at 22.33.26

    Here’s how to use the interface:

    • use the cursor keys to move up and down
    • use the SPACE bar to select items
    • use TAB to choose the next option
    • and once selected, hit RETURN

    Screen Shot 2015-02-10 at 22.33.52

     

    system-config-firewall has several built-in presets, such as DNS, FTP, Mail, standard and secure http ports and many others. If you need to open a specific port, hit Add on the “other” screen and define both the port and the protocol. In this example I’m opening port 3306 for incoming MySQL traffic:

    Screen Shot 2015-02-10 at 22.39.30

    Step forward through all available options, or select Close to move back to the first screen. Make sure the Firewall Enabled option is ticked, then hit OK and all your rules will be saved.

    The Desktop Version

    If you have Gnome or KDE installed, you can invoke the Desktop Version from the command line like this:

    sudo system-firewall-config

    In addition, there should also be a handy menu item under System – Administration – Firewall which will start the same thing.

    Screen Shot 2015-02-10 at 22.48.05

    The options are much the same, perhaps a little easier on the eye and easier to select. In addition you have a Wizard which will let you start your firewall rules with a clean slate (great if you’ve been previously poking around on the command line, potentially messing things up).

    Screen Shot 2015-02-10 at 22.48.53

    Thousand thanks to all the developers who have written this tool: Thomas Woerner, Chris Lumens, Florian Festi, Brent Fox and many others.





     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel