This article will explain and provide more information on basic SSH commands to start administrating your server via SSH. Here you will find just a fraction of the available SSH commands, however, they are most commonly used.
1. ls
Shows all the files and directories that are in the directory you are in.
Examples:
Shows all the files and directories and more information about every file:
Shows all the files that ends with ".html":
2. pwd
Shows full path to the directory you are in.
3. cd
Go into/change the directory into a different one.
Examples:
Brings you back into the home directory:
Changes the directory into /var inside the server:
Go one step back out of the directory:
Go one step further into the directory (directory above):
- cat
Shows the content of the chosen file.
Example:
Shows the content of the "index.html" file:
- chmod
Used to change the privileges of the users/groups to the file.
Examples:
No one will have privileges to access "config.html" file:
Only this user can use the file and others do not have privileges for it:
The file is accessible for everyone:
- chown
Changes the owner of the file or group.
Examples:
Changes the file's "config.php" owner into root:
Changes the owner of the "config.php" and group to root privileges:
chown root.root config.php
- tail
The same as "cat" command, but also shows the end of the file.
Examples:
Shows the last 20 lines of the file /var/log/messages:
Shows the last 100 lines:
Works the same way as "cat", but shows only as much text as fits to the window.
Example:
Shows only that part of text that fits to the window opened. For entering another page, need to press "SPACE" bar on the keyboard. For escaping, need to press "q":
- pico
Simple file editor.
Example:
Opens up the "index.html" file for editing:
pico /home/useris/public_html/index.html
10. w
Shows who is connected to the server right now.
11. top
Shows the most relevant information on server resources in real time (RAM, uptime, top processes and others).
12. touch
Creates an empty file.
Example:
Created a file "contacts.html" in directory "/home/useris/public_html/":
touch /home/useris/public_html/contacts.html
- mkdir
Creates a directory.
Example:
Creates the directory "/photos:
14. cp
Copies files.
Examples:
Copies the file's "index.html" content into the file "index2.html" when they are on the same directory:
cp index.html index2.html
Copies all the files from "/public_html/test/" directory into "/public_html" (one directory lower):
cp -a /home/useris/public_html/test/* /home/useris/public_html/
- mv
Moves the files to another directory. Usage is similar to "cp" command.
- rm
Removes/deletes the files.
Examples:
Removes the "index2.html" file:
Deletes the "index2.html" file without asking if you really want to remove it ("force"):
Removes all the files that ends in ".html":
- clear
Clears the window of SSH console.
- exit
Exits the SSH console and disconnects from the user.
- tar
Used to create file archive or extract files from it.
Examples:
Extract the file:
Extract the file:
Collects all the files in the "test/" directory and moves it into "test.tar" archive:
Unzips the specific file:
- history
Shows last 50 used commands
- wget