This article provides an overview of basic SSH commands to help you start administering your server via SSH. These commands are some of the most commonly used, though many more exist.
1. ls
Lists all files and directories in the current directory.
Examples:
2. pwd
Displays the full path of the current directory.
3. cd
Changes the current directory.
Examples:
Go to the home directory:
cd ~
Change to the /var
directory:
cd /var
Go back to the previous directory:
cd -
Go up one directory level:
cd ..
4. cat
Displays the contents of a file.
Example:
- Show the contents of "index.html":
cat index.html
5. chmod
Changes the permissions of a file.
Examples:
Deny all access to "config.html":
chmod 000 config.html
Only the owner can access "config.html":
chmod 100 config.html
Grant all permissions to everyone for "config.html":
chmod 777 config.html
6. chown
Changes the owner and/or group of a file.
Examples:
Change the owner of "config.php" to root:
chown root config.php
Change both the owner and group of "config.php" to root:
chown root:root config.php
7. tail
Displays the last part of a file.
Examples:
8. more
Displays file contents one screen at a time.
Example:
- View "/var/log/messages" one page at a time. Press "SPACE" to go to the next page, "q" to quit:
more /var/log/messages
9. pico
Simple text editor.
Example:
10.
w``
Displays who is currently logged into the server.
11. top
Shows real-time system information, including resource usage and active processes.
12. touch
Creates an empty file.
Example:
13. mkdir
Creates a new directory.
Example:
- Create the directory "photos":
mkdir photos
14. cp
Copies files or directories.
Examples:
Copy "index.html" to "index2.html":
cp index.html index2.html
Copy all files from "test/" to the parent directory:
cp -a /home/useris/public_html/test/* /home/useris/public_html/
15. mv
Moves files or directories. Usage is similar to cp
.
16. rm
Removes files or directories.
Examples:
17. clear
Clears the terminal screen.
18. exit
Logs out of the SSH session.
19. tar
Creates or extracts file archives.
Examples:
20. history
Displays the last 50 commands used.
21. wget
Downloads files from the internet.
Example: