Below are Ubuntu Linux commands I use often to setup, debug maintain servers.
Read this guide for Useful OSX Commands (for setting up Apache, PHP, MySQL, Adminer etc on OSX)
I recently moved my domain from a C-Panel hosted domain (and Email to Google G Suite (my guide here)) to a self-managed Digital Ocean domain (my LetsEncrypt Guide here, my Digital Ocean guide here, my AWS setup guide here, my Vultr setup guide here) and needed to transfer my WordPress site. Setup your own Digital Ocean Ubuntu server form $5 a month (get the first 2 months free by clicking here) or setup your own Vultr Ubuntu server for as low as $2.5/month by clicking here.
How to Reboot (from time to time when prompted with *** system restart required ***” messages appear).
How to set up a bash file (*.sh) as Executable.
The file will now be executable.
Viewing your crontab (Windows Task Scheduler equiv)
Ping a port
Rename a folder
Set the owner of a folder
Check the rsync port
Run a file every 1 minute
Show server name
How to verify patch status for Meltdown and Spectre
Read my guide here to install the patch here.
Verify Spectre and Meltdown patch status
or
Restart network
More here.
Show Operating System Name
hostnamectl ! grep "Operating System" Operating System: Ubuntu 10.04.3 LTS
Show installed Packages
Show all packages with “PHP” in the name.
Send Messages Other Logged In Users (CLI)
Show all user logged in
Sent a message to usr1
Sent a message to the root console
Messages will appear at the bottom of the user’s console.
Processor
List processes in a tree view (… = removed)
View major processes by usage/memory
Read more on ps here.
How big is a folder
Change FIle Create/Modify time’s
Change File Creation Date
Change file modify/accessed time
Tree
Tree needs to be installed first
Show an ASCII representation of a folder structure
Show files in a structure
Show directories
List all files and folders in a structure
Backup a www folder
Common (Digital Ocean) Debugging commands
Networking
Display all TCP connections
Display all UDP connections
List all Listening Connections
Show all Network stats
Show all UDP Network stats
Show all TCP Network stats
Show network packets
Displaying raw info
Show open ports
Upload a file to a remote server over ssh
Zip files
Install zip
Zip a whole directory (with high compression)
Zip a whole directory (excluding *.tmp, *temp, *.bak and *.zip file types)
Zip Help
Backup NGINX
Unzip
Installing Unzip
Unzip a file
unzip filename.zip
Updates
Setup Unattended Ubuntu Security updates
At login, you should receive
Show Configured NGINX server names
Services
Reload daemon services
Verify the MongoDB service file exists
View the status of services
Local Dump
Show All Defined Ports
Show defined rsync ports
Show listening ports (active connections)
Show service status
View your bash history for a past command (e.g “openssl”).
grep "openssl" ~/.bash_history openssl req -new -newkey rsa:4096 -nodes -keyout fearby.key -out fearby.csr
View last 1 line of a file.
Ping a server
How to check system uptime (and load average)
Uptime in friendly format
The load averages at the end are the last 1, 5 min and 15 minutes.
The w command is handy for showing uptime information as-well as logged in users (The ‘w -i’ parameter -i is handy for seeing what IP people are logged in from).
How to download a file
How to edit NGINX configuration
sudo nano /etc/nginx/nginx.conf
and
How to find a file
also
locate php.ini
Find contents in files (recursive)
Find files by name and run a command on each
Show differences in files
Show contents of file (e.g urls.txt)
cat urls.txt http://www.server1.com http://www.server2.com http://www.server3.com http://www.server4.com http://www.server5.com
Download all files mentioned in a text file.
View all packages with updates
Output:
or (on ubuntu 16.04)
Updates
Always backup your server’s configuration before updating.
Backup MySQL
Crontab
Add this to crontab -e to backup at 1 am every day
/scripts/shrinkmysql.sh script to shrink SQL files
I had to add this to crontab
Cron job to shrink SQL dumps at 2am every day
Write to a single log file from the crontab at 2 am every day.
todo
Query a package (e.g. siege package)
How to set up a free SSL certificate (see my guide here).
How to set your timezone.
How to restart PHP
How to show the time on the server
sudo hwclock --show
Reload and restart the NGINX configuration and web server.
JSON viewing program
Installing
Using
or
Below are utilities I use a lot.
ncdu file size utility
Installing
Using
pydf disk checking utility
Installing
Using
ntp timezone service
Installing
Using
Displaying startup processes
Installing
Using
htop process manager.
Installing
Using
Network Benchmarking (between two servers)
I use iperf to measure total bandwidth between two servers. You will need to allow port 5001 (TCP IPV4 and TCP IPV6 in and out) in any local firewalls and hosts GUIs.
Allow port 5001 on an ufw firewall (IN and OUT)
Deny IP
Allow port 22 access to known IP
Deny Outgoing Port
Allow out on port to known IP
More securing Ubuntu in the cloud here.
Install iperf on the target and source Ubuntu server.
Run this on the listening server.
Run this on benchmarking server (and add the IP of the listening server).
iperf -c 123.123.123.123
Results
Testing concurrent connections to a web server with siege.
Install siege
Benchmarking a HTTP server
./siege -t1m c10 'https://fearby.com' #10 Concurent users
Benchmarking HTTPS sites
Install siege 4.0.2 ( steps here ).
Verify siege 4.0.2 is installed by running
Now can benchmark https sites
View incoming connections on the target server
I always increase my history size and tell it not to store duplicates.
Viewing your typed terminal history
Increasing your history size
How to Update Ubuntu
or
Edit SSH authorized keys
Search file and show lines where text matches
View packages with updates
View Boot Text
Automatic Monitoring (ever 1 second)
Active network connections
Network Packets
Free memory
Memory breakdown
or
Monitor NGINX memory
more soon…
Read this guide for Useful OSX Commands (for setting up Apache, PHP, MySQL, Adminer etc on OSX)
50 most useful Linux commands (view here).
View other Linux command informing sites here, here and here.
Donate and make this blog better
Ask a question or recommend an article
[contact-form-7 id=”30″ title=”Ask a Question”]
v1.8 Show users and senda messages to other users
v.71 Show Operating System Name
v1.7 added Meltdown and Spectre patch information
v1.6 Removed -x fom zip directory
V1.5 Restart Network
v1.4 added Useful OSX Commands