19 Popular SSH Commands
What is SSH?
SSH stands for Secure Shell which is a network protocol that allows computers to securely communicate with one another. Even over insecure networks, SSH keeps communication encrypted and enables the safe transfer of data. SSH is typically used via the command line however there are certain graphical user interfaces that allow you to use SSH in a more user-friendly manner.
With the power of SSH, you can also run certain commands from one computer on a remote machine. This allows you to list files in a certain directory, copy files, move files, and much more. In this guide, we'll cover some of the most popular SSH commands
Popular SSH commands
Knowing how to use the following SSH commands will greatly help you when doing anything with SSH. If you don't use SSH very often, it's important to keep a cheat sheet like the following one handy so that you aren't lost the next time you need to complete a task.
cd - Change directory (e.g.
cd /var/www will put you in the
cd ~- Go to the home folder
cd /- Go to the root directory
cd -- Go to the previous directory
cd ..- Move up one directory
ls - List files
ls -a- List all files in a directory
ls -h- List files along with file sizes
ls *.html- list all files ending in
pwd - Show full path according to where you are right now
cat - Show the contents of a file (e.g.
rm - Delete a file (e.g.
rmdir- Delete a folder (e.g.
mv - Move a file (e.g.
mv index.html /mydirectory/index.html)
mv- Move and rename a file (e.g.
mv index.html /mydirectory/newname.html)
cp - Copy a file (e.g.
cp index.html /mydirectory/index.html)
cp- Copy a file and rename it (e.g.
cp index.html /mydirectory/newname.html)
mkdir - Create a new folder (e.g.
vim - Open or create a file with the Vim text editor (e.g.
vim filename.html). Learn more about Vim in our Vim commands guide.
nano - Open or create a file with the nano text editor (e.g.
touch - Create a file (e.g.
grep - Search for a string (e.g.
grep "word" index.html). Searches for "word" in the
wget - Download files and store them in your current directory (e.g.
zip - Compress a folder (e.g.
zip -r folder.zip folder). Takes "folder" and compresses it as a file called "folder.zip"
unzip - Decompresses a folder (e.g.
chmod - Change a file's permissions (e.g.
chmod 604 folder)
netstat - Display network connections
free-m - Display your machine's current memory usage
exit - Exit the remote server and return to your local machine
If you're going to be using SSH you'll need to create and define your SSH key pair. This includes a public and private key. These keys are required in order for the connection between your local machine and the remote machine you're connecting to is secure. Creating SSH keys is a fairly simple process and only requires that you run a few commands. To learn more about them, check out our guide on how to create SSH keys.
With the SSH commands cheat sheet in this article, you should now have no reason to not know your way around an SSH client. Of course, the more you use SSH the less likely you'll need to reference this but for those don't use it frequently, a cheat sheet can be a big time saver. Let us know below what common SSH commands you use.