Introduction
As a web developer, having the right set of tools is crucial. When it comes to Ubuntu Commands for Web Servers, knowing the right commands can save you time and system resources. This article aims to provide you with the most useful Ubuntu commands for effective web server management.

Understanding sudo
The sudo command allows you to run programs with the security privileges of another user, typically the superuser (root). For example:
sudo apt-get updateThis command updates the package list on your system, a task usually reserved for the superuser.
File and Directory Operations
Navigating and manipulating the file system is a daily task for any web developer. Here are the essential commands to perform these operations.
List directory contents
lsChange directories
cdCopy files or directories
cpMove or rename files and directories
mvRemove files or directories
rmCreate empty files
touchCreate directories
mkdirChange file permissions
chmodChange file ownership
chownThese commands are essential for navigating and manipulating your server’s file system.
System Information
Monitoring your system’s health is crucial for effective web development. These commands will help you keep an eye on your system.
Display system information
unameReport file system disk space usage
dfEstimate file space usage
duDisplay the amount of free and used memory
freeDisplay dynamic real-time system status
topKeep an eye on your system’s health with these useful commands.
Package Management
For software package management, the following commands are indispensable. They offer a way to add, remove, and manage the software on your system.
APT package handling utility
apt-getQuery the APT cache
apt-cachePackage manager for Debian
dpkgEfficiently manage your software packages with these commands.
Network Operations
Network operations are critical for any web server. Use these commands to monitor and manage them.
Check network connectivity
pingNetwork statistics
netstatDisplay or configure network interfaces
ifconfigThese are your go-to commands for monitoring and managing network operations.
MySQL Operations
Database management is a key aspect of web development. These MySQL commands allow you to efficiently manage your databases.
Log into MySQL
mysql -u root -pCreate new database (schema)
create database [dbname]Create a new MySQL user
create user '[username]'@'localhost' identified by '[password]'Grant privileges to the new user
grant all privileges on [dbname].* to '[username]'@'localhost'List all databases, show all databases
show databasesSelect a database
use [database]List tables in the selected database
show tablesExit MySQL
exitManage your MySQL databases efficiently with these commands.
SSH Operations
Secure your server and optimize remote operations with these SSH commands.
Connect to a Server via SSH
Connect to a server via SSH, where [username] is root or your own SSH user and [hostname] is typically your server’s IP address:
ssh [username]@[hostname]example:
ssh root@yourserverIPaddressCreate a New SSH User
Once connected with a superuser, you can create a new SSH user:
adduser [username]Generate SSH Keys for the New User
Now, switch to the new user’s account and generate SSH keys:
su - [username]
ssh-keygenFollow the prompts to complete the key generation. This will create a new SSH key, using the provided email as a label.
Disable the SSH Root User
For security reasons, it is recommended to disable your SSH root user:
sudo passwd -l rootRestart SSH Service
After disabling the root user, it’s a good practice to restart the SSH service:
sudo systemctl restart sshdUFW Cheat Sheet = Firewall Operations
UFW is an abbreviation for Uncomplicated Firewall.
The below commands are not necessarily based on a step by step guide.
Check the Firewall Status: To see the current rules, you can use:
sudo ufw statusEnable UFW
sudo ufw enableThis will list all the rules that are currently active.
Allow SSH Connections
sudo ufw allow sshDeny All Incoming Connections by Default
sudo ufw default deny incomingAllow All Outgoing Connections by Default
sudo ufw default allow outgoingAllowing Specific IPs: If you want to only allow SSH traffic from a specific IP address, you can do:
sudo ufw allow from YOUR_IP_ADDRESS to any port 22Delete the general OpenSSH rule: You’ll first need to identify the rule number. To do this, run:
sudo ufw status numberedDelete the Rule: Use the rule number to delete it.
sudo ufw delete [rule_number]Deny All Other SSH: To deny all other SSH traffic, you can use:
sudo ufw deny 22Enable/Disable Rules: Any changes you make won’t be active until you enable them:
sudo ufw enableIf you ever need to disable the firewall for troubleshooting, you can do:
sudo ufw disableReload UFW: For the changes to take effect.
sudo ufw reloadPlease make sure you are very careful when altering firewall rules, especially over SSH, as it’s possible to lock yourself out of your own server if not done correctly.
Systemctl Operations
Start a service
systemctl start [service]Stop a service
systemctl stop [service]Restart a service
systemctl restart [service]Check the status of a service
systemctl status [service]Manage system services and units effectively with these systemctl commands.
Conclusion
Having this cheat sheet of Ubuntu commands can significantly ease your web server management tasks. For more tips like this, feel free to follow me on Twitter.
Something missing?
If you think I missed something or looking for something specific, feel free to comment on the article and let me know.