WordPress on Amazon EC2: Connect to an Instance via SSH

This is part of my Introduction to Hosting WordPress on Amazon Web Services (AWS) tutorial.

In this tutorial we are going to go over the steps needed to connect to a virtual server (in this case an EC2 instance from Amazon Web Services) over Secure Shell (SSH) using the command line. In my case I am using the macOS Terminal, which is Unix-based, but the commands will be the same regardless of what command-line interface you are using.

  1. Open the macOS X Terminal, found in Applications > Utilities.
  2. Use the cd (change directory) command to navigate to the location where you keep your private keys, or .pem files. (Key pairs for AWS EC2 instances are distributed as .pem  files if you are using macOS).
  3. If this is the first time using the private key file, you will need to use the chmod command to set the permissions for the file so that it is not publicly viewable. Type: chmod 0400 pemfilename.pem (where pemfilename.pem is the name of your own pem file).
  4. Type ssh-add pemfilename.pem and press Enter.

    • The response should be Identity added: pemfilename.pem (pemfilename.pem).
  5. Type ssh -i “pemfilename.pem” ubuntu@ec2-12-345-678-90.us-east-2.compute.amazonaws.com (the actual address of your own EC2 Instance will differ based on its IP address and availability zone).

    • You can get the IP address for your EC2 instance from the Public DNS (IPv4) field from the Descriptions tab for your instance on the EC2 Dashboard.
  6. Since I am using the WordPress Certified by Bitnami Amazon Machine Image (AMI), when I connect I am greeted by a Welcome to Ubuntu message.
  7. You may not be sure what directory the connection opens to. Type ls (list) and press Enter to see what’s in the current directory.
  8. In the case of WordPress Certified by Bitnami, the WordPress installation is in bitnami/apps/wordpress/htdocs, so type cd apps and then enter ls again to see what’s in apps.
  9. Type cd wordpress, press Enter, and enter ls again.
  10. Type cd htdocs, press Enter, and enter ls again. Users with some WordPress experience will recognize the file and directory names as the top level of a WordPress installation.
  11. One reason you may want to SSH into a server is to edit its configuration file. As an example, we can edit the WordPress installation’s wp-config file. Type sudo nano wp-config.php.
  12. This will open the wp-config.php file and make it editable on the command line. The wp-config file is one of the most important files in a WordPress installation, and a user may have several changes they want to make.
  13. To save any changes, hold down the control key and press o (^o) to “Write Out” or save any changes. Press Enter to save the file with the same file name.
  14. Hold down the control key and press x (^x) to exit the wp-config file.
  15. Type exit to end the SSH session.