Skip to content


Some useful things for Linux server management

I let this stash in my draft folder for long enough, adding “chapters” as I found helpful new thingies. Time to release it I guess…

Must-have hidden nano shortcuts

Go to end of file: Ctrl + W + V
Go to beginning of file: Ctrl + W + Y
Go to a specific line: ATL + G (or CTRL + SHIFT + [hyphen]), then type the line number
Delete a whole line: Ctrl + K
Even more shortcuts on The Nano Text Editor.

Commands to stop/start/restart/reload stuff

This may vary depending on distributions, but the general idea is:
/etc/init.d/[service name] [stop|start|restart|reload]
For instance:
/etc/init.d/mysqld restart
It is to be noted that reload is a great feature, which I tended (I still do, but to a lower extent) to overlook. It allows you to apply new settings without restarting the server. So in the huge majority of cases, you can use it instead of restart and avoid some downtime while applying new settings.

Addendum: on OpenSUSE, to restart OpenSSH: /etc/rc.d/sshd restart

Some key files/folders locations

The logs (Apache, SMTP, etc) are in /var/log.
The received e-mails (including e-mails sent to the server itself via cron jobs) are in /var/mail (then each user has one big text file where e-mails get stashed.

My current ~/bashrc file

Mainly useful for the update shortcut 😉

# ~/.bashrc: executed by bash(1) for non-login shells.

# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022

# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
alias au='apt-get update && apt-get upgrade'
alias logap='cd /var/log/apache2'
alias loggo='goaccess -f /var/log/apache2/access.log'
alias loggo2='goaccess -f /var/log/apache2/other_vhosts_access.log'
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

Getting a snapshot of current connections

Might be useful to look for suspicious traffic, like, when checking for an infection.
netstat -nap
Found about it on this page of Spamhaus Composite blocking list (CBL), “How to find BOTs in a LAN”.

Find in which package is some specific executable you need

Not really server management, but pretty damn useful because of the high frequency at which you may encounter bloody error messages such as “[executable X] missing” without any help on where the fuck to find it whatsoever. The command to find in which package is some specific executable, in OpenSUSE, is:
cnf [executable name]

How to compute password for .htpasswd file

Basic authentication via .htaccess requires you to hash passwords somehow. A simple way to obtain the hashed password is to use the htpasswd utility. For instance: htpasswd -ns username

How to rename a user account

You can use usermode, and/or edit manually the relevant files, mainly /etc/passwd, /etc/group and /etc/shadow. Don’t forget to move around the home folder, too.
See also: Crazytoon – How do you rename a user account in linux?

How to install all dependencies of a package

This can be useful when you want to compile said package manually, but have issues finding out/installing all required dependencies. Of course you could just install the package then remove it and compile the newer version, but that seems cleaner this way: apt-get build-dep r-base.

Update (2023-02-11): dealing with “The following packages have been kept back” when running apt-get update

That infamous error message has regularly been bothering me. Then for a long while, sudo apt-get --with-new-pkgs upgrade used to do the trick.
Not anymore in the recent years. Neither does the reportedly risky sudo apt-get dist-upgrade. Neither does “waiting a few hours because these are phased updates“, as I’ve had packages kept back seemingly forever.
There is always the option to do sudo apt-get install [package name(s)], but I really really don’t like it as it then marks these packages as “manually installed”, which makes it impossible to keep track of what I really want installed and what was just supposed to be a dependency (hurray for that monstrous horrific concept that is the package manager).

Anyhow, what’s been working for me lately is simply adding the package names to the update command: sudo apt-get update [package name(s)]. I don’t really get why this solution isn’t suggested anywhere though, I hope I’m not breaking anything I’ll only notice in years, but so far it’s been all good.

Posted in Linux, servers.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA