alan

ancientwisdom

This is one very, very, very interesting piece of ancient wisdom.

Suppose you need to change permissions for some directories. Maybe the permissions are too strict, e.g. something like 700 for directories and 600 for files, and you need to give access to some other group and not just the owner.

As you know, execute permission on directories is required for traversal. So you might think doing something like:

chmod -R g+rx /var/somedirectory

This would probably work, but would leave you in a sad state: you'll get the executable bit set on files that are not supposed to be executable at all, which may be just annoying but may get risky as well.

A great alternative is:

chmod -R g+rX /var/somedirectory

the capital X means: set the executable bit only if the target a) is a directory b) has already at least one executable bit set for any one of user, group, others.

There's another alternative that may be appealing in some situations, at least when you want to give the group the same permissions as the owner:

chmod -R g=u /var/somedirectory

This will give any file the group permissions identical to the user's permission.

#MostlyUnixish #linux #ancientwisdom #chmod

A desktop freeze is something that's not so rare nowadays – that's not good, but we shouldn't get desperate about that.

I like Compiz with Unity Desktop on my Ubuntu Trusty very much; I feel it's a step forward compared to traditional desktops. The only major nuisance I had on the previous versions was the inability to disable the global menu (which I like by itself, but I don't like the global menu disappearing when the mouse is not over it), but you can now disable it and have the menu on the window – even though you can't still enable an always-visible behaviour.

The problem is: compiz sometimes gets buggy. Running a different window manager, like metacity and/or xcompmgr just doesn't seem good, you can experience other issues and you're using the stack in a way it wasn't designed for. I don't like that approach.

So, what can you do when your desktop freezes? The symptoms are usually very clear: you can move your mouse, but you can't click nor type anything.

You don't need to reboot nor to restart X. You can fix this without losing your work.

Get a raw tty

Press Ctrl+Alt+F1 and get to a raw linux console, and login with your credentials. Make sure you use the same user you're logged into X with.

Find and kill your stuck process

pgrep compiz

This will print the PID of our stuck window manager.

Let's kill it

pkill compiz

This won't usually be enough because the process is really stuck: if you repeat the pgrep command above, you'll find it still running – i.e. pgrep will return the very same PID as above.

So let's kill it, really this time!

pkill -9 compiz

Then wait some 15-20 seconds.

Now, if you repeat the pgrep , you'll either see a) no result or b) a different PID.

If you see a different PID, it's Ubuntu that noticed the crashed process and relaunched it; press Ctrl+Alt+F7, and you should just get back a working desktop!

Relaunching

If you see nothing with pgrep, you'll need to relaunch Compiz manually.

You cannot simply relaunch compiz on the console, because it must connect to X: the proper way to do it is:

DISPLAY=:0 compiz

Now switch back to your X instance with Ctrl+Alt+F7 and enjoy!

#MostlyUnixish #linux #ancientwisdom #community #ubuntu #compiz

I seem very ancientwisdom-oriented these days.

Sometimes you've got a system user on your linux server that's used to run a specific service; it's a good practice to employ those users to achieve privilege separation, since it limits the impact of many security breaches. It's security 101, really.

If you've got a system user, most probably its shell would be /bin/false or /bin/nologin. Again, this is a good practice, since it would be harder for an attacker to gain shell access to your machine through that user.

But I find that many people just change such shell, because sometimes they need to customize the environment for a user, and if you try doing something like

su - systemuser

you'll find yourself just back to your original shell, because su tries to invoke the shell which is set for the target user, and sudo doesn't generally help here, because its --shell option doesn't start a proper login shell for that user (most of the environment is that of the calling user).

Very well, gentlemen: this is a wrongdoing and a potential security hole. You should never enable a shell for your system users. Instead, you should leverage an option of su:

su - systemuser --shell /bin/bash

That lets you choose your favourite shell on a per-launch basis.

#MostlyUnixish #linux #ancientwisdom #su #security

This is another old trick, but I like to tell the world about such amenities.

I often find people writing command lines such as:

ssh arcane-system-user@someextremelylong.andimpossibiletotype.anderrorprone.hostname.com

or, worse

ssh idliketorememberwhichuser@10.20.30.40

or maybe it was

ssh someuserimashamedof@1.2.3.4

yes, sometimes ssh is simply tedious.

But you can do better. In fact, you can do much better.

your ~/.ssh/config or /etc/ssh/ssh_config can contain Host configuration sections; I have already blogged about such directives when I told the world about stopping key verification compliants – they're very flexible, indeed.

Consider adding Host directives in your configuration for your most used services:

Host myniceserver
    Hostname myniceserver.mylove.com
    Port 12345
    User teddybear

And then you can just

ssh myniceserver

You can override most options on a per-server basis and/or select a certain private key for connections.

#MostlyUnixish #linux #ssh #ancientwisdom