Secure Shell (ssh) on Linux Servers – Beginner’s Guide

Wikipedia defines Secure Shell as

Secure Shell (SSH) is a cryptographic network protocol for secure data communication, remote command-line login, remote command execution, and other secure network services between two networked computers that connects, via a secure channel over an insecure network, a server and a client (running SSH server and SSH client programs, respectively).

For a layman it is similar to what you see as “Command Prompt” on Windows PC or Terminal in Mac OS X. By using ssh, you can login to your server and access files and folders in your account in text format instead of graphical interface. This feature is for Advanced Users for powerful control of their web hosting account.

Most of the tasks related to web hosting can be done using cPanel or FTP. However some tasks are more conveniently done using ssh e.g. editing .htaccess file for mod_rewrite rules.

You need ssh client on your computer to login to an ssh server. There are free and commercial software available. For Windows, putty is a popular free ssh client. It does not even need to be installed. You can download putty.exe file and run it on your computer.

When you are running putty, it will ask you to enter following information of the remote server to connect to it:

Host Name (or IP Address): This is your server IP address or domain name.
Port: 22 (You may need to check with your hosting provider if this port does not work. They may have set it to a different port for security reasons).
Connection type: SSH

Click Save to save the session settings for future connections.

Click Open to make a connection to the remote server.

First time you connect, it will issue a Security Alert:

The server’s host key is not cached in the registry. You have no guarantee that the server is the computer you think it is…..

This is normal for the first time. When you click Yes and continue, it will be cached for future connections.

Enter your ssh username when prompted with login as: (this is typically your cPanel username)

Enter password. If ssh is allowed for your account, you’ll be in ssh environment and can issue linux shell commands. If it is disabled or you enter wrong password, access will be denied. Please contact support for help. When you login successfully, it will also print a line that Last login: showing you the last date/time when someone logged into this account and the IP address of the user.

If you are on Mac OS X or Linux computer, you can go to Terminal and issue a command like this ssh username@IP

Where username is your cPanel username, and IP is your server IP address. If ssh is on a different port then the command would be
ssh -pXXX username@IP
Where XXX is the ssh port.

Once you are logged in, you can issue linux shell commands. Below is a short list of important commands.

CommandMeaning and description
pwdprint absolute path of current working folder
cdchange folder to home folder
cd public_htmlchange folder to public_html. This is typically where your website files reside. You can replace public_html with other folder names to move around.
cd ../Move up one folder in the folder (directory) tree.
clearclear the screen so you can enter new commands without any old output on it
rm xyz.txtremove (delete) xyz.txt file
cp xyz.txt abc.txtCopy xyz.txt file as abc.txt (for making a duplicate or backup of the file)
mv abc.txt xyz.txtRename file abc.txt as xyz.txt
uptimeDisplay the current time with how long the server has been up and running since last reboot
hostnameDisplay server’s hostname
lsList all files in current folder. ‘dir’ also works as replacement command
ls *.jpgList all files with names ending in .jpg in current folder
exitLog off your shell