Our Premium, VPS and Dedicated hosting plans come with SSH access. This article describes how you can connect to your server via SSH. First though, let’s talk about what SSH is and whether or not you should use it.
The term SSH can refer to either the SSH protocol or the
ssh utility. As a protocol, SSH provides a method to securely connect to another computer. The
ssh utility is one of a number of Linux utilities that use the protocol. Other utilities that can use SSH include rsync and sftp.
SSH is primarily used to connect to a command line shell on a remote server. From there, you can perform just about any task. You can use tools such Composer and WP-CLI, export and import databases, run custom scripts and much more.
ssh utility is only useful if you have a good understanding of the Linux command line. As a rule of thumb, don’t use SSH if you are (relatively) new to the command line. And please, do not blindly copy and paste commands from some random website without understanding what the commands actually do. Let us do the work for you instead. We are a managed hosting company and always happy to help.
To connect to a server via SSH your computer needs to have an SSH client installed. The
ssh utility is installed by default on Unix-like operating systems such as macOS, Linux and BSD. Until late 2018 getting SSH to work on Windows typically required using PuTTY, but you can now finally connect to servers via
ssh in PowerShell. If you are on Windows, you may want to run this command (as an administrator) first:
Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
The output should show that
OpenSSL.Client is installed. If it is not then you need to enable it:
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
The basic command to connect to a server is:
To illustrate how to use SSH we will connect to the domain example.com on our cpweb6 server. The user for the domain is example and the server’s hostname is cpweb6-premium.active-ns.com. That means we can connect like so:
[localhost ~]$ ssh firstname.lastname@example.org
For the cpweb6 server that wouldn’t work though, as the server doesn’t listen for incoming SSH connections on the default port (22). You can use the
-p option to specify the port you want connect to. For instance, you can tell
ssh to connect to port 2222:
[localhost ~]$ ssh -p 2222 email@example.com The authenticity of host '[cpweb6-premium.active-ns.com]:2222 ([220.127.116.11]:2222)' can't be established. ECDSA key fingerprint is SHA256:JEDa817fgEReGADSzmipl9FgnIKXR2. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '[cpweb6-premium.active-ns.com]:2222,[18.104.22.168]:2222' (ECDSA) to the list of known hosts. firstname.lastname@example.org's password: [example@cpweb6-premium ~]$
As this was the first time we connected to the server the authenticity of the remote host wasn’t known. This is why, in the above example, our local machine asked whether or not we wanted to continue. After typing “yes” the remote server’s public key was added to the ~/.ssh/known_hosts file on our local computer.
After that we were prompted for the user’s password, and we then got a command line prompt on the remote server.
Once you are logged in you can start exploring the shell environment. Here are some commands you might want to run:
[example@cpweb6-premium ~]$ whoami example [example@cpweb6-premium ~]$ id uid=1031(example) gid=1033(example) groups=1033(example) [example@cpweb6-premium ~]$ pwd /home/example
The output shows our user name (example), our user and group ID and the current working directory.
It is also worth checking what shell we are using and where executables may be installed:
[example@cpweb6-premium ~]$ echo $SHELL /bin/bash [example@cpweb6-premium ~]$ echo $PATH /usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/cpanel/composer/bin:/home/example/.local/bin:/home/example/bin
As you can see, we got a standard Bash shell and we can store executables in either the ~example/.local/bin or ~example/bin directory. The directories may not yet exist – if so you can simply create the directory.
Of course, you can also check if common text editors are installed:
[example@cpweb6-premium ~]$ type nano vi emacs nano is /usr/bin/nano vi is /usr/bin/vi -bash: type: emacs: not found
In this case nano and vi are installed, but emacs is not.
You can also check what PHP version is installed and which extensions are available:
[example@cpweb6-premium ~]$ php -v PHP 7.2.27 (cli) (built: Feb 4 2020 09:15:33) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.27, Copyright (c) 1999-2018, by Zend Technologies [example@cpweb6-premium ~]$ php -m | grep -i phar Phar
The output of
php -m is rather long, so in the last example we just checked if the Phar extension is installed (it is).
If you are going to use SSH regularly it is worth looking into setting up key-based authentication for SSH. Not only is using SSH keys more secure and convenient, it will also give you more knowledge of how SSH works.