centos | centos basics

Basics of centos server administration.


Yum Cheatsheet

redhat


Check and configure timezone

cd /usr/share/zoneinfo

Find the right timezone file in this folder. For example,

ls /usr/share/zoneinfo/Turkey

Backup old localtime file

sudo mv /etc/localtime /etc/localtime.bak

Copy the new one:

sudo ln -s /usr/share/zoneinfo/Turkey /etc/localtime

Run date from the command line, and ensure that the appropriate time, date, and timezone are reported.

date

Reference:

blog


Change default editor to nano

yum -y install nano

echo "set nowrap" >>/etc/nanorc

Now

cat <<EOF >>/etc/profile.d/nano.sh

export VISUAL="nano"

export EDITOR="nano"

EOF

Log out and back in to activate the changes.
Reference:

wiki


Enable color command-line

nano ~/.bashrc

add the line:

PS1='\[\033[02;32m\]\u@\H:\[\033[02;34m\]\w\$\[\033[00m\] '

If you want add the following to the ls line

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


Change hostname

hostnamectl set-hostname "Your-Hostname"

Edit /etc/sysconfig/network and add the line:

nano /etc/sysconfig/network

HOSTNAME=Your-Hostname

Also change /etc/hosts

nano /etc/hosts

Restart and check

cat /etc/hostname

hostname

hostnamectl


Change root password:

passwd root

Add new user and change password.

adduser username

passwd username

Change rights of username:

usermod -aG wheel username

If you need to see a list of users:

cat /etc/passwd

sudo cat /etc/shadow

last | grep user

lid -g wheel

To delete a user, keep/delete his files:

userdel username

userdel -r username


To disable root SSH login:

sudo nano /etc/ssh/sshd_config

and get the line:

PermitRootLogin no

Restart ssh:

sudo service sshd restart


Change SSH port from 22 to 2345:

sudo nano /etc/ssh/sshd_config

and get the line:

Port 2345

You need to change firewall:

firewall-cmd --add-port 2345/tcp

firewall-cmd --add-port 2345/tcp --permanent

Also update selinux:

semanage port -a -t ssh_port_t -p tcp 2345

Restart ssh:

sudo service sshd restart

Reference:

wiki    wiki   


Update system:

sudo yum update


Check if there is a swap file:

sudo swapon -s

Create a 4GB swap file:

sudo fallocate -l 4G /swapfile

or the slower:

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

Check:

ls -lh /swapfile

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:

sudo nano /etc/fstab

/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

sudo nano /etc/sysctl.conf

vm.swappiness=5

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

digitalocean


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  


CentOS repo config files are here:

ls /etc/yum.repos.d

Edit any .repo file here and add the following line to enable:

enabled=1

Read more about repos:

wiki


Install programs

sudo yum install p7zip screen zip unzip bind-utils net-tools lsof curl nmap whois ethtool iotop iptraf ioping ncdu psmisc

sudo yum install p7zip lm-sensors smartmontools dmidecode hddtemp

Find out which package provides a command:

yum provides PROGNAME

yum whatprovides PROGNAME


Change home folder permissions:

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

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

Edit

sudo nano /etc/login.defs

and set the umask value:

umask 026


To reduce systemd log entries, edit:

sudo nano /etc/systemd/system.conf

and add change the line:

LogLevel=notice

Now:

sudo service rsyslog restart

sudo systemd-analyze set-log-level notice

References:

blog    archlinux