Pages

Friday, May 2, 2014

Basic SSH

If you have an account on a cPanel server with shell access or your own VPS or Dedicated server running Linux then SSH is a powerful tool to have in your skill set.

SSH (aka Secure Shell) is a way of logging into your server from a remote computer such as your home desktop or laptop. The remote connection utilizes encryption on both the server’s end and your end to keep the entire session secure.

The most common type of connection that our support department uses is to SSH into a server as the root user. Logging in as root allows you to make systemwide changes, restart important services, and perform many other tasks that only the root user is allowed to do (by default).

If you are going to initiate your remote connection from a Linux or Mac OS X computer you can start using SSH by opening up the Terminal application. Linux users should know how to find the terminal, and Mac OS X users need only open their Applications folder and then the Utilities folder to find Terminal.app. Unfortunately SSH is not built-in to Windows, so you will need to download an application like PuTTY.

Once your terminal is open you can start your SSH session as root using the following command:


ssh root@host.servername.com

This commands tells your computer “I want to open a new SSH session to the server called host.servername.com, and I want to log in as the user root.”

If this is your first time connecting to the server using this hostname your SSH client will ask if you are sure you want to connect to a new, previously unknown host. Say “yes” and you will be prompted for the root account’s password (or simply, root password). After you have typed in the password and it is accepted you will be logged in to the server as the root user.

Before you continue, it is important to note that logging in to a server as root is a powerful but also potentially DANGEROUS system administration tool. The root user is allowed to change/delete practically everything in a server without any type of warning or confirmation of changes being made. Always backup your files before you modify them using a simple backup command:


root@host [~]# cp file file.bak

For new shell users, the above command breaks down like so:

root@host [~]#

The prompt. Shows you your username (root) and the name of the server you are logged into (@host). For example: If you were logged into a server called webstuff1 and your username was bill, your prompt might display bill@webstuff1.
       
The [~]# indicates the directory you are currently looking at/working in

cp
The copy command. Tells the server to copy the file to a new file with a different name, or the same name but in a different location (path).

file
The file that you want to backup.

 file.bakThe new copy of the file that will be created. You can also specify a new location like /home/username/file.bak .
   
To review, the above command creates a copy of “file” in the same location as the original and calls it “file.bak”.

No comments:

Post a Comment