I’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:
gzip: stdin: notingzip format
tar: Childreturned status1
tar: Erroris notrecoverable: exitingnow
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:
[massive list of files goes here]
Another Linux mystery solved – thanks to Justin Solver for this tip!
In 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:
This will give you one of two “targets”, either
multi-user.target (the command line), or
graphical.target (the Windows-like GUI)
To change from one to the other, use one of these commands:
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:
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:
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:
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:
reboot system boot2.6.32-504.8.1.eTueFeb1018:51-08:05(4+13:14)
reboot system boot2.6.32-504.8.1.eTueFeb1011:27-18:50(07:22)
root tty1 TueFeb1011:16-down(00:09)
reboot system boot2.6.32-504.8.1.eTueFeb1011:15-11:25(00:10)
reboot system boot2.6.32-504.8.1.eTueFeb1010:59-11:25(00:26)
root tty1 TueFeb1010:29-down(00:28)
reboot system boot2.6.32-504.el6.iTueFeb1010:28-10:58(00:29)
wtmp begins TueFeb1010:28:532015
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:
versluistty1:0ThuNov1911:21still logged in
Or if you’re only interested in restarts:
reboot system boot2.6.32-573.8.1.eThuNov1911:20-12:02(00:41)
reboot system boot2.6.32-573.8.1.eTueNov1712:43-12:02(1+23:18)
reboot system boot2.6.32-573.7.1.eTueNov1711:12-12:42(01:29)
reboot system boot2.6.32-573.7.1.eSatOct3123:34-12:42(16+14:07)
reboot system boot2.6.32-573.1.1.eSunAug909:08-23:33(83+14:24)
reboot system boot2.6.32-504.23.4.TueJun3018:02-09:07(39+15:05)
reboot system boot2.6.32-504.8.1.eSunFeb1511: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.
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 example.com)
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 example.com--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:
Ever wondered if there’s a difference in overhead and memory usage when you’re using a VM instead of OS X directly? Here’s a comparison for website hosting.
The above graph shows the difference of hosting one of my websites for the last few days on OS X Server (in blue) that I got from Hostgator (using their HostGator Thanksgiving Deal 2016 coupon), and in a CentOS VM under Parallels Desktop 10 on the same hardware (in red).
The traffic logs show that the amount of requests and visitors has remained the same, so we can deduce that the load put on either OS X and the VM is the same. There is a little more overhead when using the VM, but not as much as I had feared: the requests have to be forwarded to another software layer after all, and that takes some CPU power.
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).
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.
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:
If you’ve read my previous article about how to enable automatic logins on CentOS 6, and it sounded a little daunting, you may be pleased to hear that it’s a little easier to accomplish the same thing on CentOS 7.1.
If you’re using GNOME in a single user environment, and you’re confident that nobody else will use your system, you can enable auto-logins without the password questions like this:
Login to GNOME as usual
Find your name at the top right and click on it
Now select Settings
In the new window that opens, find Users
Click on Unlock at the top right
Select your own user and turn on Automatic Logins
You need supervisor privileges to make this change. Next time you restart your system, you’re logged in automatically.
I like setting up barebones CentOS and other flavoured VMs on my Mac via Parallels Desktop. Trouble is, for such things like time synchronisation to work properly, something called Parallels Tools needs to be installed on each VM.
This is to make sure Parallels Desktop can speak to the VM and communicate with it properly. It’s more important for GUIs so that the screen resolution and mouse handling is more accurate.
Thing is, when you have a VM with a GUI, installing Parallels Tolls is extremely easy and may even happen automatically as soon as you install the OS. But if you have a command line only interface, it just doesn’t happen, and it’s up to us to install those tools manually. Here’s how to do it in CentOS 6.
First, boot up your barebones VM and wait for it to start. Now head over to the VM’s menu and choose Actions – Install Parallels Tools. If they’re already installed, this message will change to “Reinstall Parallels Tools”.
If your VM has a graphical user interface, this process will kick off the actual installation, but on barebones machines, it will merely attach the ISO image that contains the tools to your VM. In an ideal world, this tool would even mount the image for us, but sadly it doesn’t work with CentOS. Therefore we have a bit more work to do until we get to the installation part.
You’ll see the following message to confirm the attachment:
Now let’s login to our VM as root using our favourite SSH client (or simply use Parallels Desktop). We’ll create a directory to which we can mount the image. As suggested in the Parallels documentation, we’ll use /media/cdrom:
With this directory in place, let’s mount the ISO image to it so we can address it:
mount: blockdevice/dev/sr0 is write-protected,mounting read-only
The message is fairly self-explanatory: no writing to that ISO image. No problem! To start the installation, enter the directory and call the install script like so:
Help! That’ didn’t work!
Sometimes (in CentOS 7 for example) the ISO image isn’t properly mounted, and instead Parallels Desktop mounts a directory containing the ISO image. That’s no good of course. If you receive an error message along the lines of “command not found”, take a look at the CD Rom’s directory with the ls command.
If there is no file called “install”, and instead there’s something like “prl-tools-lin.iso”, you need to manually attach the ISO image to your VM. To do this, restart your VM and select Devices – CD/DVD 1 – Connect Image. Now navigate to Applications – Parallels Desktop.app – Contents – Resources – Tools and pick the appropriate ISO file.
For all Linux flavours this is prl-tools-lin.iso. Once attached, mount the device as discussed above and you should be able to run the installer.
Parallels Tools TUI in action
The script will greet us with a TUI and some steps we need to complete, one of which may be that some additional components (such as make and gcc) need to be installed. That’s not always the case on barebones systems. Lucky for us, the script will take care of this for us too:
And that’s it! The script will finish fairly quickly, and at that point, Parallels Tools is installed in your VM. Congratulations! There’s only one final step: reboot the VM. You can either do that from the VM’s menu under Actions – Restart, or by issuing the following command:
Broadcastmessage from root@yourserver
Thesystem is going down for reboot NOW!
As soon as the VM is back up and running you’re all set 🙂
Plesk uses ProFTP as the default FTP server. It has a handy feature that allows file uploads to resume or append should a connection be broken during transmission. This means that partially transferred data doesn’t have to be uploaded again, it can simply be added to – potentially saving a lot of time.
Although easy to activate, this feature is not enabled by default on Plesk installations for security reasons. Here’s how to make it happen:
Edit /etc/proftpd.conf and add the following few lines:
# allow resuming file uploads
You may find the AllowOverwrite directive in there already, in which case replace it with the above block. For the changes to take effect, restart the xinetd service (of which proFTP is part):
service xinetd restart
Works on both CentOS 6 and CentOS 7.
Note that for this to work, it also needs to be enabled in your FTP client. In FileZilla it’s under Settings – Transfers – File Exists Action: