Basic shell commands after Putty SSH logon
With the rise of control panels over the years administering a server has become less challenging for beginners in the wonderful Linux world. You have WHM/cPanel, DirectAdmin, Webmin, ISPConfig, Vesta etc… control panels that ease the server management to a level that everyone will find suitable.
On the other hand, managing a server without control panel knows to be tricky. The server owner must have at least basic understanding and knowledge of Linux administration and commands.
So in this article we will cover some basic points, commands and ways to connect to your Linux VPS via SSH.
– You have access to a user that you can connect with via SSH (usually root)
– You have Putty (Windows) on your machine or access to a terminal (Mac, Linux)
Windows users can log into their server using Putty which is a free SSH, Telnet and Rlogin client. Putty can be downloaded here.
No setup is required – it is a standalone executable. Run Putty, enter your IP address into the Host Name (or IP address) field, the port on which your server SSH service is listening, SSH for protocol and then click on Open.
You will be prompted to enter the user that you plan to access your server with and then the respective password.
Linux/Mac users on the other hand can use their build in terminal and log into their server using the below command syntax:
# ssh root@IP_address -p port_number
This example command will try to log into the server as root with the p argument being the port that the SSH service listens to. If you don’t use -p then it will try to connect on the SSH default listening port (22).
There, so now you are logged into your server via SSH with the help of Putty or your terminal.
One thing that springs to mind after the initial logging is: Where am I?
To check in which directory you are currently residing you can use the pwd shell command. For example:
# root@vps:~# pwd /root
PWD stands for ‘print working directory’. As you can see from the output above, the current working directory for the root user is /root.
Now let’s navigate to another directory from the Linux tree hierarchy. Let’s say that you want to be in the directory where all the OS configuration files can be found or /etc. Type:
# root@vps:~# cd /etc
after which you will immediately be in the /etc directory as shown in the output below:
# root@vps:/etc# pwd /etc
Now you want to see what does this directory contain. Which files and directories are present. For that you will need to list the content of the current directory. Use the ls command. This command has many options that you can combine with. For example if you want to list the files plus hidden ones by the time they are modified you can type:
# ls -lat
If you used this command in the /etc directory you will find it troubling to check the latest modified files due to the output from this command being large because of the many directories and files in place. Therefore use ‘less‘ in conjuction with ls -lat. Execute:
# ls -lat | less
| is a pipline that makes the output of one command serve as the input of another command which gives you possibilities to combine different commands altogether. So in the above example you are combining the listing command with the less command which will list only a small number of the directories/files in a single page output. To navigate and check the rest of the listing you can use Page Down. To quit this command use Q.
Now let’s go back up one directory. To do that use:
# cd ..
Now navigate to the /root directory. Type:
# cd /
What if you want to create a file? There are many ways to do that. To create a file type:
# touch rosehosting.html
This will create a file which will be empty. To populate it you can use one of the many text editors in Linux such as vim, vi, nano, emacs etc…
Of course every text editor has it’s own modus operandi so feel free to use an editor according to your needs and knowledge.
To create a directory use the mkdir command:
# mkdir /opt/wordpress
This creates a wordpress directory into /opt. To delete the directory use rmdir. However you cannot use rmdir if the directory is not empty, so you will have to either empty the directory content first or use another command to delete everything along and inside the directory. We are talking about a very dangerous command that needs to be used wisely. You probably know already about ‘rm -rf’ whose arguments instruct the command to delete everything in the path provided. So for the sake of the argument, let’s delete the newly created full wordpress directory.
First check where you are with ‘pwd’ to ensure that you are located where you should be or in the /opt directory. If not there use the ‘cd’ command to navigate to /opt:
# cd /opt
Then list the content of the directory with ‘ls’ and after you are sure that you are where you created the wordpress directory, execute:
# rm -rf wordpress
This above command will delete everything in the present wordpress directory. However, if you type /wordpress instead of wordpress then it will delete a directory which if exists will be located in the Linux tree hierarchy as the output below shows:
drwxr-xr-x 24 root root 4096 Jun 5 10:38 ./ drwxr-xr-x 24 root root 4096 Jun 5 10:38 ../ drwxr-xr-x 2 root root 4096 May 31 15:18 bin/ drwxr-xr-x 2 root root 4096 Apr 12 20:14 boot/ drwxr-xr-x 6 root 500 680 Jun 5 08:12 dev/ drwxr-xr-x 94 root root 4096 Jun 5 08:15 etc/ drwxr-xr-x 4 root root 4096 May 18 20:12 home/ drwxr-xr-x 12 root root 4096 May 13 22:34 lib/ drwxr-xr-x 2 root root 4096 Apr 21 03:53 lib64/ drwxr-xr-x 2 root root 4096 Apr 21 03:53 media/ drwxr-xr-x 2 root root 4096 Apr 21 03:53 mnt/ drwxr-xr-x 3 root root 4096 Jun 5 08:26 opt/ dr-xr-xr-x 72 root root 0 Jun 5 08:12 proc/ drwx------ 12 root root 4096 Jun 5 10:24 root/ drwxr-xr-x 17 root root 520 Jun 5 08:19 run/ drwxr-xr-x 2 root root 4096 May 31 15:18 sbin/ drwxr-xr-x 3 root root 4096 May 17 19:33 srv/ drwxr-xr-x 7 root root 0 Jun 5 08:12 sys/ drwxrwxrwt 9 root root 4096 Jun 5 10:35 tmp/ drwxr-xr-x 10 root root 4096 Apr 21 03:53 usr/ drwxr-xr-x 12 root root 4096 Apr 29 10:18 var/ drwxr-xr-x 2 root root 4096 Jun 5 10:38 wordpress/
To rename a file you can use the ‘mv’ command.
For example let’s rename the created rosehosting.html file. Since you were located in the root directory when you created the file using touch, you now have to use the following command to rename the file:
# mv /root/rosehosting.html /root/bestmanagedvps.html
So, you use mv, then the file you want to rename and then the value to which you want to rename the file into.
mv can also be used to move files from one directory to another. Example:
# mv /root/bestmanagedvps.html /var/www/html
which will move the bestmanagedvps.html file into /var/www/html
This article and command examples are just a glimpse of the possibilities that Linux commands offer. You can check another article we wrote about basic Linux commands here. Also, another article of ours show 5 of the most used network troubleshooting commands.
If you have any additional questions on Linux commands, feel free to leave a comment below. You can always get a Linux VPS hosting service from us and our fully-managed support will help you with everything regarding Linux administration, configuration and troubleshooting.