Mastering Server Management through SSH
Introduction
Get to know the command line: Linux CLI basics. Navigating your Pressillion server via SSH might seem daunting initially, especially if you’re not a developer.
However, SSH access is an invaluable tool, granting direct server management capabilities.
This guide aims to demystify SSH and equip you with essential commands for efficient server management on Pressillion.
Part 1. A Quick Introduction to SSH
SSH (Secure Shell) enables secure connections between computers. On Pressillion, SSH is the primary method for server access, ensuring encrypted, secure interactions between your local machine and servers.
SSH and WordPress
While FTP/SFTP provides file access, SSH allows file viewing/editing, zipping/unzipping, database backups, and more—offering fast, secure, and efficient server management. It’s favored by sysadmins for WordPress site management.
Connecting to your server by SSH
Guides are available for creating SSH keys and adding them to servers.
Follow these steps:
Part 2. Navigation – Commands you’ll use a lot
Mastering key commands for server navigation is fundamental for effective management:
ls – The list command
Use ls
to list directory contents:
ls -l
– Display detailed information including permissions.ls -a
– Show all files including hidden ones.ls -lh
– List with file sizes in human-readable form.
cd – Change Directory
Navigate directories with cd
:
cd ~
– Go to the root directory.cd ..
– Move to the directory above the current one.cd -
– Return to the previous directory.
Arrow keys, Home & End
Use arrow keys for quick command history access and Home/End for navigation.
Part 3. Active Server Management Commands
Learn commands for making changes to your server actively:
Create a directory
Use mkdir
to create a directory:
mkdir mynewdirectory
– Create a new folder in a specific location.
Creating new files
Utilize touch
to create files:
touch newphpfile.php
– Generate a new PHP file.
Copy
Duplicate files/folders with cp
:
cp main-context.conf /_custom/main-context.conf
– Copy a file to a new location.cp -f
,cp -i
,cp -n
– Variations for different copy scenarios.
Move
Transfer files/directories with mv
:
mv SOURCE DESTINATION
– Move files to a specified destination.- Various options for moving and renaming files.
Viewing the contents of existing Files
View file contents using cat
, head
, tail
:
cat wp-config.php
– Display entire file contents.head
,tail
,tail -f
– Show parts of a file or view in real-time.
Remove (delete) stuff
Delete files/folders using rm
:
rm myoldfile.txt
– Remove a specific file.rm -r directoryname
– Delete an entire directory and its contents.
View File sizes
Check disk usage with du
:
du -h
,du -sh
– Display disk usage in a human-readable format.
View System Disk Space
Check system disk space using df
:
df -h
,df -T
– View disk space usage in a human-readable format and system file types.
Part 4. Creating and editing files
Create/edit files using nano
:
nano newphpfile.php
– Open a PHP file for editing.- Use
CTRL+O
,CTRL+X
to save and exit in nano.
Part 5. Working with Compressed Files
Manage compressed files, zipping, and unzipping operations:
Zip
Use zip
to compress directories:
zip /var/www/example.com/htdocs
– Zip a directory.zip -m filename.zip foldername
– Compress and delete the original.zip -d filename.zip foldername
– Delete a file from an existing zip archive.
Unzip
Unzip files using unzip
:
unzip filename.zip
– Unzip a file.unzip filename.zip -x excludeme.ext
– Exclude specific files/directories.unzip filename1.zip filename2.zip filename3.zip
– Unzip multiple files simultaneously.
List the contents of a Zip File
View contents of a zipped file with unzip -l
:
unzip -l filename.zip
– Display contents of a zipped file.
Creating Tar Files
Create tar files for archiving:
tar -cf tarfilename.tar /target/directory
– Create a .tar file.tar -cvf tarfilename.tar /target/directory
– Create a .tar file with verbose output.tar -cvzf tarfilename.tar /target/directory
– Compress while creating a .tar file.
Extracting Tar Files
Extract tar files:
tar -xf tarfilename.tar
– Extract a .tar file.tar -xvf tarfilename.tar
– Extract a .tar file with verbose output.
Part 6. Searching your system
Discover files/data within your server:
find
– Find files and directories
Locate files using find
:
find starting/path criterion "search term"
– Search for specific files/directories.- Examples using
find
command for searching directories and files.
grep
– Search files by content
Use grep
to find content inside files:
grep searchword/term filename
– Search for a word/term in a file.- Various options like
-i
,-c
,-n
,-l
for different search scenarios.
Part 7. Monitoring your system
Monitor server activity using built-in tools like top
and htop
.
Part 8. Other useful commands
Additional commands for various server tasks:
wget
– Download from a website
Download files from external sources with wget
:
wget OPTIONS URL
– Options for downloading files.
pwd
– Print name of current/working directory
Display the current directory path with pwd
.
Clear your terminal window
Clear the terminal window for a neat interface:
- Use
clear
command or pressCTRL+L
.
Part 9. The Linux Manual
Access the Linux manual (man
command) for in-depth information on commands:
man whatis
– Display a one-line manual page description.- Lookup commands directly in the Linux manual for comprehensive details.
Part 10. Exit
To disconnect from servers:
- Use
exit
.