Basic server setup
1. Update packages
After the first login, usually you want to update and upgrade the installed packages:
apt update
apt upgrade --yes
apt install vim tmux git mosh psmisc asciinema
# do also a reboot, in case the kernel is updated
reboot
2. Fix vim settings
Enable the dark background setting of vim
:
sed -i /etc/vim/vimrc \
-e 's/^"set background=dark/set background=dark/'
3. Set a better prompt
The default prompt is usually dull and boring, and a nice prompt makes your work easier. So let’s try to improve it:
# customize ~/.bashrc
sed -i ~/.bashrc \
-e '/bashrc_custom/d'
echo 'source ~/.bashrc_custom' >> ~/.bashrc
cat <<'EOF' > ~/.bashrc_custom
# set a better prompt
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]\$ \[\033[00m\]'
EOF
We have created the file ~/.bashrc_custom
, which we source
(include) at the end of ~/.bashrc
.
4. Enable colorized ls
In Debian we should enable colorized ls output (on Ubuntu it is
enabled by default). Edit ~/.bashrc
and uncomment ls
aliases.
sed -i ~/.bashrc \
-e 's/^# export LS_OPTIONS/export LS_OPTIONS/' \
-e 's/^# alias ls=/alias ls=/' \
-e 's/^# alias ll=/alias ll=/' \
-e 's/^# alias l=/alias l=/'
5. Enable bash-completion
Strange, but on an Ubuntu server it is not enabled by default (in Debian it is already enabled).
# make sure that bash-completion is installed
apt install --yes bash-completion
cat <<'EOF' >> ~/.bashrc_custom
# enable programmable completion features
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
source /etc/bash_completion
fi
EOF
6. Change the hostname
Edit /etc/hostname
, change the hostname, and reboot
.
Instead of rebooting you can also run hostname newhostname
, then
exit
and re-login.
7. Fix the limit of open files
In Linux everything is a file, and if you install lots of containers and applications, the number of files that need to be opened increases. Make sure that the limit of open files is not small:
cat /proc/sys/fs/file-max
echo 9223372036854775807 > /proc/sys/fs/file-max
To make this change permanent, append this line to
/etc/sysctl.conf
:
echo "fs.file-max = 9223372036854775807" >> /etc/sysctl.conf
Then enable it with sysctl -p
.