MainWP Community

How to Setup SSH Key Pairs & use them to connect CodeGuard to a WordPress Website

[UPDATED VIDEO HERE] - Connecting to CodeGuard ( SFTP cPanel )

Warning: This is an Advanced Topic - If this tutorial does not help, please ask your host for more help as every server is different with different rules in place and they would know the answers.

If your credentials are all correct & you get the error “Lost connection. The connection to your MySQL server was lost or killed.” Follow this Document when speaking with your Hosting Company to make sure they can confirm things are setup correctly. I can’t connect using a SSH tunnel, but I know my credentials are correct – Support Center

Other Options if this is to difficult

Option 1

Use FTP & Direct MySQL instead. You would only need your cPanel Credentials & wp-config.php credentials to connect.

Option 2 ( Advanced ) 

How to Setup SSH Key Pairs & use them to connect CodeGuard to a WordPress Website

Private Key (Note: CodeGuard only supports unencrypted RSA and DSA keys so do NOT use a passphrase when asked )

1.) Create a Public/Private Keypair via ssh-keygen ( So you are not forced by your host to Encrypt it with a passphrase; most do )

  • Within Windows PowerShell OR Linux Terminal type the command :
    ssh-keygen -t rsa

  • Open those two files in a Text Editor of your choice
    id_rsa is your Private Key that you use on CG
    id_rsa.pub is your Public Key that you put on your server

2.) Install the public key as an authorized key on your server

  • Log into cPanel
  • search for SSH
  • upload your Public Key ( id_rsa.pub )

3.) Upload your Private key to CodeGuard

  • Website URL
  • Select SFTP
  • SFTP Server ( Usually ftp.yourdomain.com )
  • Username is your cPanel Name
  • Password is your cPanel Password
  • Click add private key & paste your private key
[Siteground Caveat] - SSH port is 18765

Database Connection

4.) Whitelist CG within MySQL

  • Go back to cPanel
  • Search for “Remote MySQL”
  • Add CG IPS
    54.174.115.171
    54.174.153.212
    54.174.91.34
    54.236.233.28
    54.236.233.46

5.) Open your Wp-config.php for MySQL Creds

  • Database Hostname: Usually your server IP
  • Enter in Database Name
  • Enter in Database Password
  • MySQL Port keep 3306
  • ssh username cPanel
  • ssh password cPanel
  • click add private key & paste your private key in again
[Siteground Caveat] - SSH port is 18765
[Siteground Caveat] - Database Hostname Not Server IP  ( see "Remote MySQL" cPanel Tool )

5 Likes