SSH EC2-User Login Fix for WordPress Bitnami Instances

👁58views

Bitnami based WordPress EC2 instances default to the "bitnami" SSH user, not "ec2 user," causing "Permission denied (publickey)" errors. To fix this, log in as bitnami, create the ec2 user account, copy your public key to its authorized_keys file, and add ec2 user to the bitnami admins group to restore sudo privileges.

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.
~1 min read

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>