• We have a 5 STAR service and only happy clients ! 5 Star Rating
  • sales@plothost.com

Generate private and public key in cPanel for SSH access

The common way to connect to the server via SSH is to use a username and a password. But to increase security, you can use a pair of keys(a private one and a public one) to connect to the server.

The public key will be on the server. The private key will be on your computer. When you are trying to connect, the server compares the two keys. If they are the right ones, you will be able to access it.

We will show in this post how to generate the pair of keys and connect to your server with PuTTY.

To generate and use public and private keys in cPanel:

1.Log in to cPanel
2.Scroll down to the SECURITY section -> SSH Access

3.Click the Manage SSH Keys button

4.Click the +Generate a New Key button

5.You are now on a page with a title Generating a Public Key. Here, choose:
-Key Name – you can leave the default value
-Key Password – enter the password for the key and confirm it
-Key Type (RSA or DSA) – let the default value
-Key Size (2048 or 4096) – let the default value

cPanel mentions:

RSA vs DSA: RSA and DSA are encryption algorithms used to encrypt your key. DSA is faster for Key Generation and Signing and RSA is faster for Verification.

6.Click the Generate Key button. You will see a confirmation message: Key Generation Complete! with some details:

Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
b7:9a:55:59:c1:a7:6a:31:5c:9a:40:50:e9:73:24:a0

7.Click the Go Back link
8.Now you need to authorize the public key. (the Authorization Status is not authorized). Click the Manage link.

9.You will see a message The key with the name “id_rsa” is currently “not authorized” for use when connecting to this account.  Click the Authorize button. The success message is: The key “id_rsa.pub” has been authorized.

10.Click the Go Back link
11.Go to the Private Keys sections and click the View/Download link.

12.Here we will Convert the “id_rsa” key to PPK format. Enter the passphrase and click the Convert button.

13.You will see the key to be used in PuTTY. Click the Download key button and save the file to your computer (the filename is id_rsa.ppk) 

14.Now start PuTTY on your computer and go to Connection->SSH->Auth. Here, browse and select the file you saved at 13. (Private key file for authentication)

15. Click the Open button. PuTTY will connect to the server. Enter the Passphrase when asked.

16.You are now connected to the server 🙂

 
One of the most used SSH programs is PuTTY. Download it from chiark.greenend.org.uk/~sgtatham/putty/
Share this post:

Check the login history on your server

Linux has a command to allow you to see details about the last logins on the server. The command is last with a sister command lastb. We’ll discuss a little both of them.

Using the last command without any arguments and you will see the full list of logins. Linux keep this list in /var/log/wtmp. Use the command like last -n and you will see the last n logins, like:

root@web [~]# last -6
root     pts/0        192.168.2.33    Fri May 12 11:04   still logged in
root     pts/0        192.168.2.33    Wed May  3 14:42 - 16:20  (01:38)
root     pts/0        192.168.2.33    Mon May  1 07:50 - 09:07  (01:17)
root     pts/0        192.168.2.9     Fri Apr 28 12:19 - 14:29  (02:09)
root     pts/0        192.168.2.9     Thu Apr 27 06:08 - 09:17  (03:09)
root     pts/0        192.168.2.9     Sun Apr 23 11:29 - 12:20  (00:50)

wtmp begins Mon Aug 24 11:33:10 2015
root@web [~]#

To see the last logins for a specific user, use last -n user. The syntax of the command is:

Usage: last [-num | -n num] [-f file] [-t YYYYMMDDHHMMSS] [-R] [-adioxFw] [username..] [tty..]
-num = how many entries the command will show
-f = what file to use; by default the command will read data from /var/log/wtmp file
-t = look for the logins on a specific date
-R = the IP/hostname will not be displayed
-F = print full login and logout dates
-w = display full username and domains

For example, to display the last three full dates of logins/logouts for user root, use:

root@web [~]# last -3 -F root
root     pts/0        192.168.2.33     Fri May 12 11:04:30 2017   still logged in
root     pts/0        192.168.2.33     Wed May  3 14:42:05 2017 - Wed May  3 16:20:11 2017  (01:38)
root     pts/0        192.168.2.33     Mon May  1 07:50:57 2017 - Mon May  1 09:07:59 2017  (01:17)

wtmp begins Mon Aug 24 11:33:10 2015
root@web [~]#

The lastb command has the same options as last command and it will display the failed logins. This command takes data from the /var/log/btmp file. A sample output looks like:

root@web [~]# lastb -5
friends  ssh:notty    220.225.230.1    Fri May 12 00:20 - 00:20  (00:00)
friends  ssh:notty    220.225.230.1    Fri May 12 00:20 - 00:20  (00:00)
friends  ssh:notty    220.225.230.1    Fri May 12 00:20 - 00:20  (00:00)
friends  ssh:notty    220.225.230.1    Fri May 12 00:20 - 00:20  (00:00)
test1     ssh:notty    220.225.230.1    Thu May 11 00:09 - 00:09  (00:00)

btmp begins Tue May  2 19:57:23 2017
root@web [~]#

The lastb syntax is:

Usage: lastb [-num | -n num] [-f file] [-t YYYYMMDDHHMMSS] [-R] [-adioxFw] [username..] [tty..]

Share this post:

Command-line history in Linux

In Linux shell you can use the up and down keys on your keyboard to scroll through previously used commands. Once you find the command you want, you can edit it – move the cursor with the left and right keys and make the changes you want to it. When done press the Enter key to execute the command.

To see a list of the last commands, use the history command.
– use the history without any options to see ALL the previous commands (this can be a very long list)
– use the history -n  to see the last n commands (the last command in the list will be the history command itself)

root@web [~]# history 10
  944  2017-05-03 14:57:22 mysqlcheck llp
  945  2017-05-03 14:57:31 mysqlcheck roundcube
  946  2017-05-03 14:57:41 mysqlcheck -o roundcube
  947  2017-05-03 16:20:11 exit
  948  2017-05-12 11:12:13 history 3
  949  2017-05-12 11:12:31 history 5
  950  2017-05-12 11:12:45 w
  951  2017-05-12 11:12:49 free -m
  952  2017-05-12 11:12:51 uptime
  953  2017-05-12 11:12:56 history 10
root@web [~]#

– notice that you can also see how many commands are in the history. Look at the number in front of the commands. In the above example, we have 953 commands. – to see and execute the last executed command use !!

root@web [~]# date
Fri May 12 11:23:59 EDT 2017
root@web [~]# !!
date
Fri May 12 11:24:02 EDT 2017
root@web [~]#

Another tip is to use the CTRL+R to search a previous executed command. Just press CTRL+R, and you will see

(reverse-i-search)`d': date

Here type part of the command you are looking for. When you find it, press Enter to execute it.

CentOS is the most used Linux distribution in the web hosting world. It uses Red Hat Enterprise Linux (RHEL) as its upstream source. More info at CentOS page on Wikipedia
To connect to the Linux shell you can use a software like PuTTY.
Share this post:

Set up mail client to receive and send messages

To get email messages to your email client you need to use IMAP or POP3 protocol.
To send email messages from your client you will need to use the SMTP protocol.

Abbreviations used means:
IMAP = Internet Message Access Protocol
POP3 = Post Office Protocol, version 3
STMP = Simple Mail Transfer Protocol
You can find more information on these protocols on the links from the end of this post.

To find more details on how to connect with an email client to the server:

  1. Log in to cPanel
  2. Go to Email Accounts from EMAIL section
  3. Look on the list of accounts for your account, and click the Set Up Mail Client link
  4. You will see the settings for manual configuration, but you can also download auto-configuration scripts for programs like Microsoft Outlook.
cPanel Email Connection Settings cPanel Email Connection Settings

The details for email connections to the server are:

✔️ Secure SSL/TLS Settings (Recommended)
 Username: username@domain.com
 Password: Use the email account’s password.
 Incoming Server: domain.com
IMAP Port: 993 or POP3 Port: 995
 Outgoing Server: domain.com
SMTP Port: 465
  IMAP, POP3, and SMTP require authentication.

 

❌ Non-SSL Settings (NOT Recommended)
 Username: username@domain.com
 Password: Use the email account’s password.
 Incoming Server: domain.com
IMAP Port: 143 or POP3 Port: 110
 Outgoing Server: domain.com
SMTP Port: 25
  IMAP, POP3, and SMTP require authentication.

Resources:

Wikipedia IMAP Protocol
Wikipedia POP3 Protocol
Wikipedia SMTP Protocol

Share this post:
back to top