20 Top Most Used & Common SSH Commands
| |As promised, I will teach babies* to manage unmanaged server from scratch. It means I’ll try to bring those babies from zero to hero being a Server Ninja. Hence, for my early posts I will firstly write all basic things for newbie server admins should know. In this page I list all necessary, most-used and common SSH commands useful to navigate through SSH client like Putty. I believe these commands are working on any Unix-based servers.
* babies = newbies with no knowledge about Linux and server at all
If you are really a newbie, then you should bookmark this page otherwise simply skip this post.
My next plan: I will post other articles of basic guides how to do things in your server via SSH. Browse it all here.
Requirements To SSH
- A working SSH client like Putty (Windows) or Terminal (Mac and Linux)
- A working Linux-based server with SSH enabled
- A cup of coffee if you wish
- A computer with stable Internet connection
Some Conventions
- Hit Enter or Return key on your keyboard after every each command / line
- Each line is a single raw of command unless specified otherwise
- Replace domain.com with your own domain name and TLD
- Replace xxx.xxx.xxx.xxx with IP address of your own server
- Replace example paths and file names according to your server information
- If a path ends with slash “/” then its a directory
- A directory: “/path/to/directory/” will always end with slash “/”
- A file: “/path/to/file” won’t have slash “/” in the end
- A file is not always having extension in the end of the file name
OK, so lets start with the most common commands to SSH you should know..
Navigating
1. How to move into another directory
Use command below to change directory
cd [another directory]
example: move to directory “download”
cd download
2. How to go to home directory
cd ~
3. How go to the last directory you were in
cd -
4. How to go up a directory level
cd ..
5. How to show the full path of the current directory
Use this command to find out where are you currently in.
pwd
6. How to list files and/or directories in a directory
ls (just type ls and hit enter)
7. How to list all files and information
ls -al
8. How to list all files ending with certain extension
ls *.ext
example:
ls *.php
9. How to list all files and folders with detailed information including file size
ls -alh
10. How to quit and exit SSH client
exit
File Management
11. How to copy and rename file
Use this command to copy and rename a file
cp [filename] [new filename]
example: we’ll rename banner.jpg to banner728px.jpg
cp banner.jpg banner728px.jpg
example: we’ll cope banner.jpg to a folder called “ads”
cp banner.jpg ads/banner.jpg
example: copying and renaming at once
cp banner.jpg ads/banner728px.jpg
ps: original file will remain, it is just copied.
12. How to move and rename file
Use this command to move and rename file
mv [old filename] [new filename]
example: moving a file to another directory
mv banner.jpg ads/banner.jpg
example: moving a file to another directory and renaming it at once
mv banner.jpg ads/banner728px.jpg
ps: original file will be deleted as it was moved to another location
pps: you can also move a folder
example: moving “image” folder to “media” folder
mv image/ media
example: moving “image” folder to upper directory
mv image/ ..
13. How to delete / remove a file
rm [file name]
example:
rm banner.jpg
14. How to delete / remove all files in current directory
rm *
15. How to delete files with certain extension
rm *.extension
example: remove all files with .jpg extension
rm *.jpg
16. How to copy a folder with all files and folders in it
cp -r [directory] [new directory]
17. How to create new folder
mkdir [folder name]
example:
mkdir image
18. How to search for a file starting within current directory
find . -name [filename] -print
example: find a file called “banner.jpg” in current folder
find . -name banner.jpg -print
19. How to search for text within a file
grep [text] [filename]
example: find the word “sidebar” in file index.php
grep sidebar index.php
20. CHMOD – how to change file permission
chmod [permission type] [file/folder name]
example:
chmod 777 config.php
Available permission type: (below is not command)
First number is for the owner, second for the group, and third for everyone. 7 = Read + Write + Execute 6 = Read + Write 5 = Read + Execute 4 = Read 3 = Write + Execute 2 = Write 1 = Execute 0 = All access denied
I think it would be worth it if you added a ‘rmdir’ I had to look around for a few minutes to learn how to remove a directory.
thanks for your tip
Maybe:
useradd = add user
userdel = remove user? 😀
They’re not ssh commands, They are just shell commands, whether you are logged in locally or remotely. ssh has nothing to do with any of it,
This was very helpful for me. I am very new to this and just ordered a VPS yesterday and these guides are really helping me work my way around. I appreciate this simple resource you’ve put together!
Thanks a lot!
First, I would like to thank “Server Mom” for all her work and help tutorials. I started at scratch with her page, went to DO as she did, got same plan and two hours later had a functioning webserver due to her guidance….thanks so much.
i have a question not seen on any tutorials……
I have a folder on my desktop with files needed to change the zpanel template, but I dont know how to import to putty and load into “/etc/zpanel/panel/etc/styles” I know the directory is there, but am clueless how to get that folder and files into the above listed directory.
also in my FTP directory, all the folders have times on them and there is no public_html folder, yet the website is up and running, any thoughts on this…
anyone to help a crawling baby…. 🙂 thank You !!
Brian
bro USE WinSCP and u will send, delete or what do u want to make changes on root/rootvps 😉
thanx!!! you are awesome server mommy 🙂 😀
Thanks for the article, is there any way I can receive an email whenever you publish a new update?
Yeah this should be renamed to Shell Commands. None of these commands are tied to ssh, ssh is just a program that handles connecting to a remove server with encryption.
i’m a beginer….please explain the diff. between file and directory
Well,
a file is a (digital) string of 0 and 1, describing a (part) of a program or data (like a picture or an email).
A directory is a digital collection of files.
Or with other words:
file = digital document
directory = digital folder containing multiple/different digital documents
A directory may contain other directories (“subdirectories”)
Does anyone know where to find a complete listing of all shell commands? I recently wrote a blog post about using OpenSSH with Ubuntu and would like to link to a comprehensive dictionary of shell commands for beginners.
Useful article;
Thank you
thanx a lot for this info.
can you plz tell me how to uncompress any archive like zip,rar,tar etc?
Use unzip command i.e. unzip filename.zip
Thanks for a useful article. I am very proficient with Windows/DOS based machines but fairly new to Linus. These articles help me getting a running start on getting things done.
Nice and really useful stuffs documented …
Thanks:) ServerMom
I will Expect some more server commands to add on on this basic stuffs..
Nice and really useful stuffs documented …
Thanks:) ServerMom
I will Expect some more server commands to add on on this basic stuffs..
This is a useful article. Thanks
Dear servermom, i found ur blog very interesting…please keep up posting information….God bless u!!!
Thanks for being out here! I’ve barely touched server stuff in the past, and am now thrown into the thick of it, so basic command instruction is a VERY good thing, right now! 🙂
Thanks MOM 😀
Thanks for the useful stuff. Could you also explain about VI editor
A nice quick help for basic SSH command for Babies* ! 😀
Thanks Mam.
Thank you Server Mom for this useful post. I’m just starting from the scratch. Should learn more. Hope your posts will help me.
thanks. those were useful.
Thank you ! really helpful