Change Default User from system user 'bitnami' using wordpress ami

How would I change the default user from 'bitnami' to something else? I tried the following: - created a new user a, and ssh'd into a's account - su - pkill'd all the bitnami's session and processes - id bitnami - usermod -l new_user bitnami

and all i ever get is 'usermod: user bitnami is currently logged in' when i enter the usermod command

is there an easier way? is there a way I can login using a non-ssh terminal somehow? Linode had a feature where I could do this by using a java terminal which acted like a local terminal.

I'm using the wordpress bitnami ami.

Solved it for myself. Here's what I did ( this is a quick and dirty writeup, so hopefully i didn't leave anything out)

How to Rename the Default Bitnami user account

\#ssh into your instance using the bitnami username and then switch to root

ssh bitnami@example.com
su

\#create a new user first, since we can only access root while ssh'd into ec2 via another user account that is not the one that we are modifying

adduser ec2-user

\#follow prompts to set the new password

\#copy the ssh key to your new directory

cp -r /home/bitnami/.ssh /home/ec2-user/

\#change ownership of the files you just moved to the user you just created

chown -R ec2-user:ec2-user /home/ec2-user/.ssh

#Disconnect from the ssh session

exit

\#ssh back in using the new account

ssh ec2-user@example.com
ssh -i /path/to/private-key.pem ec2-user@example.com

\#now change to root since we wont be able to do usermod operations without it and ec2 isn't sudo'd.

su

\#kill all the bitnami processes

sudo pkill -9 -u bitnami

\#see if we got them all

ps -ef | grep bitnami

\# you should have at least two more processes left, which we'll deal with in the next step. These are the processes spawned by your ssh connection, so we need to kill them in a special way

bitnami   1552  1539  0 00:00 ?        00:00:00 sshd: bitnami@notty
bitnami   1553  1552  0 00:00 ?        00:00:00 /usr/lib/openssh/sftp-server

\#if you see any other processes than these, use kill -9<pid> to kill them

\#Now we can rename bitnami to the new user, leaving it with the same id

sudo kill -9<pid of bitnami sshd>;sudo usermod -l <new-username> bitnami;
#example:
sudo kill -9 1552;sudo usermod -l new_user_name bitnami;

Be sure to enter the kill and usermod commands on one line so both commands are executed at the same time without a roundtrip back to you. if you try to kill the process first, then issue the usermod command, it will throw an error. By entering them as separate commands on separate lines, the sshd process will respawn and will cause usermod to complain with the 'usermod: user bitnami is currently logged in' error message

\#now move the old files over to the new user's directory

sudo mv /home/bitnami /home/new_user_name

\#Don't forget we still must also rename the bitnami group

groupmod -n new_user_name bitnami

\#finally, you need to create a symbolic link with a name of the old user so existing paths wont break (if you skip this step , you won't be able to ssh back in using the new username)

cd /home
ln -s new_username bitnami

\#Now, start a new ssh session ( don’t close the one you're in or you may be locked out of your ec2 instance if something breaks) and try ssh'ng into with your new username

ssh -i /path/to/private-key.pem new_user_name@example.com
4 Likes

Thanks for sharing your solution.

Hello,

I am using the MEAN AMI but i think is the same.

I changed the username from bitnami to admin.
I used a temporary user called “temporary” (wich i created early), then i ssh using this temporary user and change to root user with sudo su, then i ran this commands:

sudo usermod -l admin bitnami

sudo mv /home/bitnami /home/admin

sudo chown -R admin:admin /home/admin

And now all directories and files who were owned by “bitnami” are owned by “ubuntu” and i cant change that even running chown admin file_or_directory as a root

Thanks for the help.

EDIT (i solved it):

Something happened when i did the procedure, that made kind of a mess with users and groups.
Had to set up properly the user admin, and delete user and/or gruops ubuntu and bitnami. If somebody like me struggles with this type of situation here are some tips:
First of all follows the excelent guide of @joelerr.
Use cat /etc/passwd (with grep if necesary) to see the state of your users and cat /etc/group to see the state of your groups (see any linux manual for reference to the format of those files). And then use the commands for user and/or group manipulation to set your users and groups propperly. Aparently, in my case, due to some inconsistencies the system created a new user called ubuntu. keep in mind that your new user had to have its id specified in the correspondig column in the group with its same name in /etc/group.

Hi,

From what I read in your EDIT, you were able to fix the issue, am I right? If so, thanks for sharing!

Best regards,

Javier J. Salmerón

@jsalmeron yes you are right. i was able to fix my issue. I’ll edit again to let it more clear.

Best regards!

Hi @alvahro,

We are glad you solved it. Thanks for letting us know and sharing it:

Regards