Ubuntu 18.04 server administration

Install LAMP

sudo apt update 
sudo apt install apache2
sudo apt install mysql-server
sudo mysql_secure_installation
sudo apt install php libapache2-mod-php php-mysql
sudo apt install php-cli
sudo apt-get install fail2ban
sudo systemctl restart apache2
sudo systemctl status apache2

Adding a new user

# Use adduser instead of useradd
adduser [USERNAME]

# Give permission to new directory
sudo chown -R [USERNAME]:www-data /var/www/new/directory/

# Add new user to group sftp
sudo usermod -G sftp [USERNAME]

# Grant sudo privileges to a new user
sudo usermod -aG sudo [USERNAME]

# Give yourself ownership
sudo chown [USERNAME] /var/www/directory
sudo chown [USERNAME]:www-data /var/www/directory

# Give yourself ownership recursively
sudo chown -R [USERNAME]:www-data /var/www/directory

Give a new user access to /var/www

# Add new user to group www-data
sudo usermod -a -G www-data [USERNAME]
sudo useradd -G www-data [USERNAME]

# Give existing Group write access to directory
sudo chmod -R g+w /var/www/html

Folder permission

# Change group to www-data
sudo chgrp www-data /var/www

# Set group id for subfolders (set the sticky bit for the group)
sudo chmod g+s /var/www/sitename

# Give User, Group, Others rwx permission
sudo chmod -R ugo+rwx /var/folder

# Remove User, Group, Others rwx permission
sudo chmod -R ugo-rwx /var/folder

# Give/Remove Others rwx permission
sudo chmod o+rwx /var/www/sitename
sudo chmod o-rwx /var/www/sitename

# Set 775 to User, Group, Others
sudo chmod -R 775 /var/www

Set all permission to default

# Set 660 for all files recursively including folders
sudo chmod -R 660 '/var/www'

# Set 770 for all folders
find '/var/www/directory' -type d -exec chmod 2770 {} +

Verify user and group permission

# Check user belongs to 

# Check group members
getent group www-data

# Check group members for sudo/www-data
sudo cat /etc/group | grep sudo
sudo cat /etc/group | grep www-data

Help for any command

info command-name
man command-name


Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top