Linux
How to add swap on CentOS
Check the System for Swap Information
swapon -s
free -m
total used free shared buffers cached
Mem: 3953 315 3637 8 11 107
-/+ buffers/cache: 196 3756
Swap: 0 0 4095
Check Available Storage Space
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 59G 1.5G 55G 3% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.3M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
Create a Swap File
sudo dd if=/dev/zero of=/swapfile count=10240 bs=1MiB
ls -lh /swapfile
-rw-r--r-- 1 root root 4.0G Oct 30 11:00 /swapfile
Enable a Swap File
sudo chmod 600 /swapfile
ls -lh /swapfile
-rw------- 1 root root 4.0G Oct 30 11:00 /swapfile
sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=b99230bb-21af-47bc-8c37-de41129c39bf
sudo swapon /swapfile
swapon -s
Filename Type Size Used Priority
/swapfile file 4194300 0 -1
free -m
total used free shared buffers cached
Mem: 3953 315 3637 8 11 107
-/+ buffers/cache: 196 3756
Swap: 4095 0 4095
Make the Swap File Permanent
Edit the file with sudo privileges in your text editor:
sudo nano /etc/fstab
At the bottom of the file, you need to add a line that will tell the operating system to automatically use the swap file that you created:
/swapfile swap swap sw 0 0
User and sudo
How To create a new sudo user on CentOS
First create a new CentOS user account from the command line. For example, create the marlena user account, run:
adduser marlena
Set the password for marlena user by typing the following passwd command:
passwd marlena
A new user account was created. Verify it:
id marlena
In CentOS 8 Linux server all members of the wheel group have sudo access. So all you have to do is append user account to the wheel group using the usermod command command:
usermod -aG wheel marlena
User account marlena now have sudo privileges. Verify it by running the id command or grep command on /etc/passwd and /etc/group files:
id marlena
grep '^marlena' /etc/passwd
grep '^wheel' /etc/group
How to grant or add existing user account to sudo on CentOS
Below is to give sudo access to an existing user named vivek by adding the user to the wheel group:
usermod -aG wheel vivek
id vivek
Deleting a user account in CentOS 8
userdel -r {userName}