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.

REQUIREMENTS

– 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:

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:

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:

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.