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 10:34 am on November 7, 2016 Permalink | Reply

    Categories: Linux, Python ( 89 )

    How to install Python 3 from source in CentOS 

    python-logoCentOS 6 comes with Python 2.6 installed, and CentOS 7 comes with Python 2.7. But right now, Python 3.5 is all the rage, so I thought I’d install it alongside Python 2.x on the same machine.

    Here’s how I did it.

    I’m using a CentOS 6 32 bit system here, but I’ve tried the same on a CentOS 7 64 bit rig. You need to be root or have superuser privileges to do this successfully. (More …)

  • Jay Versluis 11:19 am on November 6, 2016 Permalink | Reply

    Categories: Linux ( 89 )

    How to extract tar.xz files on CentOS 

    CentOS-LogoI’ve recently come across a tarsal files that used xz compression (namely the Python source code).

    This means that my usual way of extracting a tarsal via the command line using the following command did not work:

    tar -zxvf Python*
    gzip: stdin: not in gzip format
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now

    That had me stumped! Turns out that files with a tar.gz ending can be extracted this way (because the use gzip compression, specified by the z parameter). If tar is instructed to use this format on a tar.xz file, it fails.

    The solution: specify the xz compression, using the capital letter J, like this:

    tar -Jxvf Python*
    [massive list of files goes here]

    Another Linux mystery solved – thanks to Justin Solver for this tip!

  • Jay Versluis 11:39 am on November 3, 2016 Permalink | Reply

    Categories: Linux ( 89 )

    How to boot CentOS 7 into Command Line or GUI Mode 

    CentOS-LogoIn CentOS 7 we can use the systemctl command to select which mode the OS boots into. If you have a GUI like Gnome or KDE installed, it’s easy to boot directly into your preferred environment.

    To find out what mode CentOS is currently using, use this:

    systemctl get-default

    This will give you one of two “targets”, either

    • (the command line), or
    • (the Windows-like GUI)

    To change from one to the other, use one of these commands:

    systemctl set-default
    systemctl set-default

    What happened to runlevels?

    In previous versions of CentOS, switching boot modes was achieved through runlevels. Those were saved in /etc/inittab, but this file is no longer used by CentOS 7 and above. However, the file still exists and contains a little extra info this matter, including how to change boot modes:

    # analogous to runlevel 3
    # analogous to runlevel 5
    # To view current default target, run:
    # systemctl get-default
    # To set a default target, run:
    # systemctl set-default

  • Jay Versluis 12:57 pm on March 27, 2016 Permalink | Reply
    Tags: ,   

    Categories: Linux, Plesk ( 89 )

    How to fix “MLSD unable to build data connection” in ProFTP 

    Filezilla IconI’ve come across an odd problem today on a server that’s been working fine for all kinds of FTP traffic for many years. Turns out that today, FileZilla started complaining about explicit TLS connections (when available) and gave the following error message:

    425 MLSD unable to build data connection: operation not permitted

    Clients could still connect, but no directory content was displayed, nor was uploading new files possible. Rats, I thought. This was on a CentOS 6 server with Plesk 12 running without a hitch otherwise.

    Turns out that by default, ProFTP is configured to re-use TLS sessions – but it appears that this behaviour freaks out FileZilla, which in turn doesn’t like it and throws an error instead. This did not affect plain (non-secure) sessions.

    Thankfully, Adam Stohl knows the answer to this problem: tell ProFTP not to re-use TLS sessions. Open /etc/proftp.conf and add the following line to the bottom of the file:

    TLSOptions NoSessionReuseRequired

    The ProFTP service in Plesk is part of xinetd, so for those changes to take effect, simply restart it with this:

    service xinetd restart

    And voila, TLS connections can happen again. Thanks, Adam – you’re a life saver!


  • Jay Versluis 12:14 pm on November 19, 2015 Permalink | Reply

    Categories: Linux, Mac OS X ( 89 )

    How to see which users are logged in on OS X and Linux 

    There are two funky commands that can help us see who’s currently logged in, and what operations were performed last. Those two commands are who and last.

    Let me show you how to use them.

    The who command

    Type who at the command prompt and you’ll see a list of currently logged-in users:

    versluis tty1         2015-11-19 11:21 (:0)
    root     pts/0        2015-11-19 11:46 (

    This system has two users logged in: versluis, via TTY, and root via PTS. We also get to see which IP addresses these users are logged in from (:0 is localhost).

    On this note, TTY is the local text based terminal at the machine, while PTS is a pseudo-terminal. This is most likely an SSH session or similar, anything that’s happening remotely.

    who can also show us who we are, in case you’re ever logged in on a system and don’t know which user you are:

    who am i

    You can also concatenate who am i into whoami.

    The last command

    The last command can take a moment to execute and will show a list similar to this:

    versluis tty1         :0               Tue Feb 10 18:54 - down  (4+13:11)   
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 18:51 - 08:05 (4+13:14)   
    root     pts/1        Tue Feb 10 16:33 - 16:44  (00:10)    
    root     pts/0        Tue Feb 10 11:36 - down   (07:13)    
    versluis pts/0        :0.0             Tue Feb 10 11:35 - 11:35  (00:00)    
    versluis tty1         :0               Tue Feb 10 11:29 - down   (07:20)    
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 11:27 - 18:50  (07:22)    
    root     tty1                          Tue Feb 10 11:16 - down   (00:09)    
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 11:15 - 11:25  (00:10)    
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 10:59 - 11:25  (00:26)    
    root     tty1                          Tue Feb 10 10:29 - down   (00:28)    
    reboot   system boot  2.6.32-504.el6.i Tue Feb 10 10:28 - 10:58  (00:29)    
    wtmp begins Tue Feb 10 10:28:53 2015

    You can see who has logged in to the system recently, from which IP address, and when each session started and finished. You can also see when the system was last restarted (and in Linux, which Kernel was used to do so).

    The last line (on Linux, beginning with wtmp) shows since when the command was able to display results. last and who both read a file called wtmp (in /var/log/wtmp), which logs all login attempts over time.

    last accepts several filtering options too. For example, to query when a particular user has logged on and off, type last followed by the username:

    last versluis
    versluis tty1         :0               Thu Nov 19 11:21   still logged in   
    versluis tty1         :0               Tue Nov 17 12:44 - 22:32  (09:48)    
    versluis tty1         :0               Tue Nov 17 11:13 - down   (01:29)    
    versluis tty1         :0               Sat Oct 31 23:35 - crash (16+12:37)  
    versluis tty1         :0               Sun Aug  9 09:09 - down  (83+14:24)  
    versluis tty1         :0               Tue Jun 30 18:03 - down  (39+15:04)  
    versluis pts/0        Thu Feb 19 14:41 - 18:34  (03:52)

    Or if you’re only interested in restarts:

    last reboot
    reboot   system boot  2.6.32-573.8.1.e Thu Nov 19 11:20 - 12:02  (00:41)    
    reboot   system boot  2.6.32-573.8.1.e Tue Nov 17 12:43 - 12:02 (1+23:18)   
    reboot   system boot  2.6.32-573.7.1.e Tue Nov 17 11:12 - 12:42  (01:29)    
    reboot   system boot  2.6.32-573.7.1.e Sat Oct 31 23:34 - 12:42 (16+14:07)  
    reboot   system boot  2.6.32-573.1.1.e Sun Aug  9 09:08 - 23:33 (83+14:24)  
    reboot   system boot  2.6.32-504.23.4. Tue Jun 30 18:02 - 09:07 (39+15:05)  
    reboot   system boot  2.6.32-504.8.1.e Sun Feb 15 11:30 - 09:07 (174+20:37) 

    On OS X the output is somewhat more limited due to the absence of kernels, but it works just the same. For more information on each command, checkout the man pages with man last and man who.

  • Jay Versluis 3:31 pm on November 9, 2015 Permalink | Reply
    Tags: , Spam   

    Categories: Linux ( 89 )

    How to remove an IP from the CBL (Composite Blocking List) 

    Today I was introduced to something called the CBL, or the Composite Blocking List. This is one of several Spamhaus projects that’s there to make sure IP’s are blacklisted when they’re sending spam.

    You can check if your IP’s are OK at

    The CBL is a separate website in which you can also lookup IPs. Spamhaus will tell you if that’s the case and direct you to the CBL here:

    Even though my IP was otherwise fine, it was listed in the CBL, and Yahoo kindly made me aware of this as part of an error message I’ve received when trying to send an email. If ever there is an email problem in CentOS, the first place to look is /var/log/maillog. Here’s Yahoo’s very helpful explanation:

    Turns out that the hostname was not setup yet, so the box would respond as localhost.localdomain. That’s a big fat no-no as far as the CBL people are concerned. Here’s CBL’s explanation:

    This IP address is HELO’ing as “localhost.localdomain” which violates the relevant standards (specifically: RFC5321).

    The CBL does not list for RFC violations per-se. This _particular_ behaviour, however, correlates strongly to spambot infections. In other words, out of thousands upon thousands of IP addresses HELO’ing this way, all but a handful are infected and spewing junk. Even if it isn’t an infection, it’s a misconfiguration that should be fixed, because many spam filtering mechanisms operate with the same rules, and it’s best to fix it regardless of whether the CBL notices it or not.

    (More …)

    • N1njawtf 2:50 pm on March 20, 2016 Permalink | Reply

      Cool! thanks alot! I guess this solved my blacklisting problem.

  • Jay Versluis 1:06 pm on November 9, 2015 Permalink | Reply

    Categories: Linux ( 89 )

    How to set the hostname on CentOS 7 

    CentOS 7 has a nice command called hostnamectl. With it we can display the current hostname, and set any of the three types of hostname:

    • static hostname (something like
    • transient hostname (anything you like, assigned when using DHCP)
    • pretty hostname (something like Jay’s MacBook Pro)

    By default, a CentOS installation comes back with localhost.localdomain – but that’s not meaningful if you see lots of localhosts on the same network.

    If the IP of the box does not change, we can set the static hostname like this:

    hostnamectl set-hostname --static

    No feedback means good news. Likewise, we can set a hostname if were using DHCP to get an IP address, even though it may change every time we connect. To make sure we retain the same name no matter what IP we get, let’s set the transient hostname like so:

    hostnamectl set-hostname myserver --transient

    Note that we can’t use spaces or special characters with static or transient hostnames as far as I know.

    Lucky for us there’s also the pretty hostname, which does support special characters. It doesn’t usually appear anywhere on the command line, but GUIs like to display the pretty name of a machine when available:

    hostnamectl set-hostame "Jay's MacBook Pro" --pretty

    There’s no need to restart anything, the changes are in effect as soon as we hit return after either command.

    To see the current hostnames, we can use the status switch:

    hostnamectl status
       Static hostname:
       Transient hostname: myserver
       Pretty hostname: Jay's MacBook Pro
             Icon name: computer-vm
               Chassis: vm
            Machine ID: 3d1ed70be1e940efaab8fb63b82822cc
               Boot ID: b95807c92b904fc192bd086b2596bea5
        Virtualization: kvm
      Operating System: CentOS Linux 7 (Core)
           CPE OS Name: cpe:/o:centos:centos:7
                Kernel: Linux 3.10.0-229.20.1.el7.x86_64
          Architecture: x86_64

    Thanks to Vivek Gite for this wonderful explanation!

  • Jay Versluis 8:05 am on November 2, 2015 Permalink | Reply
    Tags: ,   

    Categories: Linux ( 89 )

    How to disable SSH access from everywhere except for certain IPs in CentOS 7 

    Here’s how to do it:

    firewall-cmd --zone=internal --add-service=ssh --permanent
    firewall-cmd --zone=internal --add-source= --permanent
    firewall-cmd --zone=internal --add-source= --permanent
    firewall-cmd --zone=public --remove-service=ssh --permanent
    firewall-cmd --reload

    This declares an internal zone with two IPs (add as many or as few as you like) and subsequently removes the SSH service from the public zone altogether. As a result, any other IP gets a message such as “Connection refused” when trying to connect via SSH.

    The “–permanent” switch saves the changes. Remove it for testing or if you don’t want this change to be permanent.

    The last line reloads the current firewall rules (thanks, CertDepot).

  • Jay Versluis 8:29 am on September 10, 2015 Permalink | Reply

    Categories: Linux ( 89 )

    How to fix a “could not bind to address” error in Apache 

    I have worked on a server recently and I came across a problem (again) that I meant to write about, and include a solution should you suffer from a similar problem. It was a Plesk server running CentOS, but this particular issue can also happen on plain LAMP stacks.

    Trying to start Apache, I got the following error message:

    apachectl -k restart
    httpd not running, trying to start
    (98)Address already in use: make_sock: could not bind to address [::]:80
    (98)Address already in use: make_sock: could not bind to address
    no listening sockets available, shutting down
    Unable to open logs

    The port number may be different depending on which port Apache is supposed to listen on (80 is the default, but depending on your system it may be something different, for example 7080). What this error is saying is that the Apache config file says the service is supposed to use a specific port, and another service is already using it. Hence, Apache can’t start or restart.

    If your server has worked fine before, then it’s likely that the config file is not the problem – so don’t go messing with it unless you absolutely know what to tweak.

    Let’s find out what service (or process) is listening on our port. We can do this using the lost command:

    lsof -i:80
    httpd   18893 apache    5u  IPv6 216716713      0t0  TCP *:http (LISTEN)
    httpd   32576 apache    5u  IPv6 216716713      0t0  TCP *:http (LISTEN)
    httpd   32576 apache  178u  IPv4 226927338      0t0  TCP> (CLOSE_WAIT)
    httpd   32576 apache  180u  IPv4 236802430      0t0  TCP> (CLOSE_WAIT)
    httpd   5135 apache    5u  IPv6  24375      0t0  TCP *:empowerid (LISTEN)
    httpd   5146 apache    5u  IPv6  24375      0t0  TCP *:empowerid (LISTEN)

    Replace the port number (80 in the above example) with your own. In this example, Apache is in fact listening but something isn’t quite right and it’s unable to restart. We can go and kill each of these processes using the following command:

    kill -SIGTERM 18893

    Do this with every process ID (PID) from the list you get from the lsof command. As soon as they’re all dead (verify with lsof), try to restart apache once again:

    apachectl -k restart

    This has helped me on a number of occasions 😉

  • Jay Versluis 11:01 am on August 14, 2015 Permalink | Reply
    Tags: ,   

    Categories: Linux ( 89 )

    How to disable the user list at login on CentOS 7 

    Screen Shot 2015-08-13 at 10.51.47

    By default, CentOS 7 will display a list of all users on the system. Click on it, type in the password, and you’re in. This works well when you have a handful of users on the system.

    However, on systems with a lot of users, not everyone can be displayed in that list – and scrolling up or down is impossible (and even if it was, it’s impractical at best). The solution is to replace that list with a box to type in a user, much like what would happen when you choose the “Not Listed” option.

    Here’s how to do it:

    From the command line, login as root and create a file called /etc/dconf/db/gdm.d/00-login-screen. By default it does not exist.

    vi /etc/dconf/db/gdm.d/00-login-screen

    Now add the following lines to it and save the file:

    # Do not show the user list

    This will tell GNOME not to display the list anymore, and instead bring up a text box as shown below. For the change to take effect, we need to update GNOME with the following command:

    dconf update

    And that’s it!

    Screen Shot 2015-08-13 at 10.54.55

compose new post
next post/next comment
previous post/previous comment
show/hide comments
go to top
go to login
show/hide help
shift + esc