👁27views
Setting up ssh for ec2-user to your wordpress sites

CloudScale AI SEO - Article Summary
  • 1.
    What it is
    This article explains how to configure SSH access for ec2-user on WordPress EC2 instances that default to using the bitnami user account for authentication.
  • 2.
    Why it matters
    WordPress builds on AWS EC2 often use bitnami as the default SSH user, which can be confusing and inconsistent with standard AWS practices where ec2-user is the norm.
  • 3.
    Key takeaway
    You can switch from bitnami to ec2-user for SSH access by creating a new user account, copying SSH keys, and adding appropriate group permissions.

So after getting frustrated (and even recreating my ec2 instances) due to a “Permission denied (publickey)”, I finally released that the worpress builds by default as set up for SSH using the bitnami account (or at least my build was).

This means each time I login using ec2-user I get:

sudo ssh -i CPT_Default_Key.pem [email protected]
[email protected]: Permission denied (publickey).

Being a limited human being, I will never cope with two user names. So to move over to a standard login name (ec2-user) is relatively simple. Just follow the below steps (after logging in using the bitnami account):

sudo useradd -s /bin/bash -o -u id -u -g id -g ec2-user

sudo mkdir ~ec2-user/
sudo cp -rp ~bitnami/.ssh ~ec2-user/
sudo cp -rp ~bitnami/.bashrc ~ec2-user/
sudo cp -rp ~bitnami/.profile ~ec2-user/

Next you need to copy your public key into the authorised keys file using:

<code>cat mypublickey.pub >> /home/ec2-user/.ssh/authorized_key</code>

Next to allow the ec2-user to execute commands as the root user, add the new user account to the bitnami-admins group, by executing the following command when logged in as the bitnami user:

<code>sudo usermod -aG bitnami-admins ec2-user</code>