EINVAL: Valid solutions for invalid problems

Emacs as a Shell

, updated on

When I log into a new server, one of the first things I do is install a minimal Emacs package1. Of course assuming nobody minds if the server is not strictly mine, I’m not a monster.

Emacs serves me as a de facto shell when setting up whatever there is to set up. By “shell” I mean a broader meaning of this word than just a command prompt: it’s the central program I use to interact with the system. Regardless of the system and its current configuration, I can expect Emacs to be predictably the same program suitable for both configuration file editing and advanced file management thanks to the built-in dired module. One could say I use it like many people use Midnight Commander (mc) though I consider it much more powerful for various reasons. Let me show you what it looks like:

less can do even more

After writing my last post I took my own advice and reread the less(1) manpage. Surprisingly I found some new really handy tricks that were very helpful not even an hour later!

First of all, the pair matching. If the topmost displayed line (that’s the important part!) contains an opening bracket {, we can press this very key to find the matching closing bracket (}). It is displayed by placing the line with the matching } at the bottom. Similarly now we can press } to find the matching { to the closing bracket in the bottom line, and it gets shown as the topmost line. At first it feels strange and confusing but it makes sense after trying it out. I used {} in my example but the same “trick” works for () and []. We can also match a custom pair (sadly, only single-character) by pressing ctrl+alt+f followed by the opening character and then the closing character, to go to the closing character and ctrl+alt+b followed by the same thing to go back to the opening character. So even though there is no key for matching <> we can use ctrl+alt+f < > to match them.

less can do more

less is probably one of the most used programs in the UNIX world. It’s so ubiquitous we usually barely notice it. For clarity, I mean this less, not this one. Despite its ubiquity, very few people actually take time to learn its less obvious but still very useful features. Let’s change that!

First of all, the & key. It prompts for a search pattern and then acts like a filter, showing only the matching lines, not unlike grep. Unlike grep though, you can change this filter without closing less and it’s generally very useful if you need to filter the content as an afterthought, if you decide you really could use a filter only after producing copious amounts of output.

Secondary login credentials

Sometimes I need to access my files on my servers using SSH/SCP from a not fully trusted device and/or application (think: a smartphone). Usually I would create a new SSH key pair so that I can easily revoke these credentials later if such need arises. But what if the used application doesn’t support SSH keys or we do not want to use them for some reason?

There is a trick supposedly used by sysadmins in the olden days, before sudo was around. I assume you’re at least aware of the /etc/passwd file that contains the basic information about all the system users. Information such as the username, historically hash of the password1, the user and group ID (UID and GID). It looks like this: