server | basics

Basics of server administration.

Reference:

ubuntu  


Check and configure timezone

date

cat /etc/timezone

dpkg-reconfigure tzdata

service cron restart

Configure NTP time synchronization

apt-get update

apt-get install ntp

ntpdate pool.ntp.org

In recent Ubuntu releases timesyncd replaces the client portion of ntpd.

timedatectl status

Reference:

ubuntu


Configure default editor

sudo apt-get install nano

sudo update-alternatives --config editor

Or Add the following line to your ~/.bashrc

export EDITOR=/bin/nano

Enable color command-line

nano ~/.bashrc

force_color_prompt=yes

If you want add the following to the ls line

alias ls='ls -hF --group-directories-first --color=auto'


Change hostname

nano /etc/hostname

nano /etc/hosts

Restart and check

hostname -s

hostname -d

hostname -f


Remove potentially duplicated ssh host keys.

rm /etc/ssh/ssh_host_*

remove the keys of this server from the client computers

ssh-keygen -R hostname

ssh-keygen -R ip

Regenerate host keys.

/usr/sbin/dpkg-reconfigure openssh-server

If this does not work you need to manually create the keys:

ssh-keygen -t dsa -N "" -f /etc/ssh/ssh_host_dsa_key

ssh-keygen -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key

ssh-keygen -t ecdsa -N "" -f /etc/ssh/ssh_host_ecdsa_key

ssh to the server with the new user and ensure that the login works.

ssh newuser@hostname


Change root password (as root):

passwd

Add new user (as root).

adduser newuser

Change rights of newuser:

gpasswd -a newuser sudo

If you need to see a list of users:

cat /etc/passwd

sudo cat /etc/shadow

last | grep user

To delete a user:

sudo deluser --remove-home user


To disable root SSH login:

sudo nano /etc/ssh/sshd_config

and get the line:

PermitRootLogin no

Restart ssh:

sudo service ssh restart


Update system:

sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade

Cleaning up of partial package:

sudo apt-get autoclean

Cleaning up of the apt cache:

sudo apt-get clean

Cleaning up of any unused dependencies:

sudo apt-get autoremove


Check if there is a swap file and add if not:

sudo swapon -s

Create a 2GB swap file on Ubuntu:

sudo fallocate -l 2G /swapfile

or the slower:

sudo dd if=/dev/zero of=/swapfile bs=1G count=2

Edit properties and enable:

sudo chown root:root /swapfile

sudo chmod 0600 /swapfile

sudo mkswap /swapfile

sudo swapon /swapfile

Make permanent by editing /etc/fstab and adding the line:

/swapfile none swap sw 0 0

Check swappiness:

cat /proc/sys/vm/swappiness

Change swappiness to a suitable number by editing /etc/sysctl.conf and adding

vm.swappiness=10

Some people also change other settings. Google them: min_free_kbytes and vfs_cache_pressure

Check network security related settings:

sudo nano /etc/sysctl.conf

To save and reload the above file,

sudo sysctl -p

Reference:

tutorialspoint   klaver   suse   cyberciti  


Install programs

sudo apt-get install p7zip p7zip-full p7zip-rar software-properties-common python-software-properties command-not-found screen unrar-free unrar unzip zip lm-sensors lsof tree smartmontools htop gpw curl nmap whois dmidecode hddtemp ethtool iotop iptraf ioping ncdu psmisc


Show IP addresses which are currently active:

ip addr

To add an address run:

ip addr add 236.243.84.73/32 dev eth0

To make this additional ip permanent edit:

sudo nano /etc/network/interfaces

and insert under the appropriate interface (e.g. "eth0") the following two lines, then reboot:

up ip addr add 236.243.84.73/32 dev eth0

down ip addr del 236.243.84.73/32 dev eth0

Reference:

hetzner


Change home folder permissions:

find ~ -type d -exec chmod 750 {} \;

find ~ -type f -exec chmod 640 {} \;

Edit

nano ~/.profile

and set the umask value:

umask 027


To reduce systemd log entries, edit:

sudo nano /etc/systemd/system.conf

and add change the line:

LogLevel=notice

Now:

sudo systemctl restart rsyslog

sudo systemd-analyze set-log-level notice

References

blog    archlinux