Cloud VPS and Dedicated Server SSH Primer
Posted by on 01 January 2013 07:15 PM
We typically expect our Cloud VPS customers to have a higher level of knowledge when it comes to managing their hosting, but if you're new to command line interfaces (CLI), that's okay too!
Using SSH (for Windows or Mac)
You can use the console in Cloud Command, but it's usually better to use a dedicated SSH client. It is helpful to remember that the console is available to you because you can use it in situations where SSH is not available (a common one being that the firewall has blocked you from connecting).
A great and free SSH client is PuTTY. You can find it here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Another option is Xshell, which is free for non-commercial use. You can find it here: http://www.netsarang.com/products/xsh_overview.html
If you're using OSX you're on a Unix-based operating system already so there's one built in, called Terminal. Open Terminal to SSH into your server.
Getting Connected via SSH
Both Xshell and PuTTY have a number of advanced features that go beyond the scope of this guide, but they're worth exploring if you have the time. To connect to your Cloud VPS:
Tip! Highlighting text adds it to your clipboard, and right-clicking will paste it into the application you're currently suing. Don't press CTRL+C to copy, as this actually cancels any in-progress actions in Linux.
WARNING: When logged in as the 'root' user there are very few things the operating system will prevent you from doing, even things that will irreparably damage the operating system, so take care when you execute commands. It's advisable to be logged in as a non-administrative user when possible, and utilize the 'su' and 'sudo' commands that require elevated permissions. Logging in as root is not inherently dangerous, but it's important to understand what you're doing.
These are specifically for our standard CentOS cPanel image, but most of the commands are universal.
cd <directory> - lets you traverse directories; example: cd / will put you in the '/' directory and cd /home/ puts you in the '/home/ directory'; using this command without any modifiers will return you to your current user's home directory
Note: you can experiment with directory traversal by cd'ing into a directory; typing ls to see the files and directories in your current directory and then changing into one of the new directories. cd .. will move you up one directory.
Resource Management Commands
Here are a few commands that can help you identify and review which processes are running on your server, and what resources they are using. Many of these commands go very in-depth but we're just providing a little info to give you an idea of what is available.
Modifying and Executing Files
There are a couple of text editors built in, and several more that you can install if preferred. Two good options are vim and Nano. Nano is a lot more user friendly so I'd suggest using that unless you specifically want to teach yourself vim. Neither is more effective than the other in terms of the end product, so it's entirely your preference. The commands to edit an existing file and the command to create a new one are the same: nano <filename>.
Linux systems have a file permission system that determines which users can access a file and what they can do with it. The permissions are broken down into three classes: the user, the group, and others. There are several bits used to determine these permissions: read, write, and execute. Each of the three classes has these permissions. If you type ls -l for example, you might see an entry like drwxr-xr-x 2 root root 4096 May 15 2012 perl5/
That entry tells us:
This may seem like a lot to take in but it's important to at least have a basic understanding. These file permissions affect how easily your site can be compromised and also can cause a lot of problems if they are configured incorrectly. Permissions can also be represented by numbers, which you will see in cPanel. 'read' permission adds 4, 'write' adds 2, and 'execute' adds 1 for the affected class. Therefore, the above example would be 755 - 4+2+1 for the owner, 4+1 for the group, and 4+1 for everyone else. This is a relatively safe configuration, because it means that only the owner of the file can modify it.
Many commands have help files that explain the command and can show you what the allowed flags are (the operators following the dash in a couple of the previous examples). To read an existing help file, just type the command followed by --help. For example, chmod --help shows the help page for the chmod command. In addition to (and sometimes instead of) the --help flag, most programs/commands have a manual page. To view it, type man <command>. The 'man page' is often much more in-depth than the help information and will often contain examples.