onsdag 7 januari 2015

Commercial software on Linux - RAR

I found that I had an old registration key for WinRAR laying around. Since I don't use Windows any more at home, I checked and found that there is indeed a commercial Linux version of the software available nowadays.

RAR is a proprietary archive format that was widely used in the 90's and the next decade when the Internet became a popular place to share software and media files. It has better compression ratio than ZIP, has strong encryption and very good error recovery capabilities. I have some memories from my time as a student of keeping a WinRAR binary on a floppy and use it to decompress and compress files transferred from and to the Internet.

I'm not going to debate over FOSS vs. commercial software in this post. If we weigh in such arguments, there are no reasons to use anything else than the LGPL licensed 7Z (p7zip) or tar with bzip2, gzip or xz (and their parallel variants), but that was not the point of this post.

There is also a freeware unrar program and libunrar library available for Linux and Unix (for Fedora in the rpmfusion repository), but it is only able to extract files from RAR archives.

To be able to create RAR archives, you have to use the official software from RARLAB. You can use it for 40 days. After this you have to buy a license key. The license is fair; software upgrades have been free (at least until now).

To easily install the RAR program (instead of downloading from the official web site and manually install it) on Fedora, there is a repository available at negativo17.org. This way also updates are nicely handled. Just add the repo file:

sudo yum-config-manager --add-repo http://negativo17.org/repos/fedora-rar.repo
sudo yum -y install rar

As far as I can tell from the RARLAB site, the license for WinRAR and RAR for Linux/Unix are the same and the later versions use the same license key. Just put the rarreg.key in your home directory (for a single user license) and begin archiving.


[1] http://en.wikipedia.org/wiki/RAR
[2] http://rarlab.com/download.htm
[3] http://negativo17.org
[4] http://negativo17.org/repos/
[5] http://rpmfusion.org/Configuration


tisdag 6 januari 2015

Preventing normal users from Shutting Down or Rebooting PC

The default policy in linux is often that normal users can shut down or reboot a PC, even if other people are logged in. When using a desktop PC as a server or if you often leave your applications open, you don't want that to happen.

This is a question that comes up many times on the Internet. The problem is that the components in linux change and not every distribution uses the same components.

In linux, only root has the power to shut down or reboot. Many linux distributions use Policykit for rules to override this and let the normal users shut down and reboot.

In Fedora 21, to override the default rules, create a new rule with the following command:
sudo nano /etc/polkit-1/rules.d/60-noreboot_norestart.rules
 Paste the following text:
polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.reboot" ||
        action.id == "org.freedesktop.login1.reboot-multiple-sessions" ||
        action.id == "org.freedesktop.login1.power-off" ||
        action.id == "org.freedesktop.login1.power-off-multiple-sessions") {
        if (subject.isInGroup("power")) {
            return polkit.Result.YES;
        } else {
            return polkit.Result.AUTH_ADMIN;
        }
    }
});
Save the file. The policy will now be in use for users logging in. It will always prevent a normal user from rebooting or shutting down the system and it will ask for the administrator user password. If you want to allow a user to shut down or reboot when no one else is logged in, modify the rules above and remove the parts "action.id == "org.freedesktop.login1.reboot" ||" and "action.id == "org.freedesktop.login1.power-off" ||". Then it will only prevent users from rebooting and shutting down when other users are logged in.


[1] At some point there was a bug in systemd that ignored the login rules, but it was fixed last year [freedesktop.org].

[2] The code in this article was copied from here [superuser.com]