frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

[Beginners] Basic SSH commands

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:
ls -al 
Shows all the files that ends with ".html":
ls *.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:
cd ~ 
Changes the directory into /var inside the server:
cd /var 
Go one step back out of the directory:
cd - 
Go one step further into the directory (directory above):
cd ..
  4. cat

Shows the content of the chosen file.

Example:

Shows the content of the "index.html" file:
cat index.html 
5. chmod

Used to change the privileges of the users/groups to the file.

Examples:

No one will have privileges to access "config.html" file:
chmod 000 config.html
Only this user can use the file and others do not have privileges for it:
chmod 100 config.html
The file is accessible for everyone:
chmod 777 config.html 
6. chown

Changes the owner of the file or group.

Examples:

Changes the file's "config.php" owner into root:
chown root config.php
Changes the owner of the "config.php" and group to root privileges:
 chown root.root config.php
7. 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:
tail /var/log/messages
Shows the last 100 lines:
tail -100
8. more

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":
more /var/log/messages
9. 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 
13. mkdir

Creates a directory.

Example:

Creates the directory "/photos:
mkdir 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/
15. mv

Moves the files to another directory. Usage is similar to "cp" command.

16. rm

Removes/deletes the files.

Examples:

Removes the "index2.html" file:
rm index2.html
Deletes the "index2.html" file without asking if you really want to remove it ("force"):
rm -f index2.html
Removes all the files that ends in ".html":
rm *.html
17. clear

Clears the window of SSH console.

18. exit

Exits the SSH console and disconnects from the user.

19. tar

Used to create file archive or extract files from it.

Examples:

Extract the file:
tar -zxvf file.tar.gz
Extract the file:
tar -xvf file.tar
Collects all the files in the "test/" directory and moves it into "test.tar" archive:
tar -cf test.tar test/
Unzips the specific file:
gzip -d file.gz
20. history

Shows last 50 used commands

21. wget

Downloads files from the provided internet link.

Example:

Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch