AWS Debian Password Reset

How to reset the Debain Maintenance password.

We took security precautions and built our LAMP and LEMP images using the MySQL secure install. This limits external access to the MySQL server from localhost only. However, even though we dynamically set the password at EC2 first creation, you may want or need to change it.

More Info: MySQL Secure Installation >>

Reset Instructions

Before you begin, copy the existing password in the file, and make a full image backup if possible.

Step 1. It is easiest to proceed from Ubuntu CLI. Connect via SSH and issue the following:

Step 2. Assuming you have not changed your MySQL Root Password or changed EC2 IDs please login with root mysql credentials.

mysql -u root -p

Step 3. After you log into MySQL issue the following commands at the mysql prompt. Make sure you copy down the new password you are issuing, you’ll need it again. You are issuing a new password and not just copying the text below.

UPDATE mysql.user

SET authentication_string = PASSWORD('TO_NEW_PASSWORD'), password_expired = 'N' WHERE User = 'debian-sys-maint' AND Host = 'localhost';

FLUSH PRIVILEGES;

exit

Step 4. From the password you set earlier update the debian.cnf file in the section that says “password =” Set to your new password and save.

sudo nano /etc/mysql/debian.cnf

# Automatically generated for Debian scripts. DO NOT TOUCH! [client]
host = localhost
user = debian-sys-maint
password = NEWPASSWORD
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = NEWPASSWORD
socket = /var/run/mysqld/mysqld.sock

Step 5. Restart MySQL Server.

sudo service mysql restart

That’s it! Contact support if you have any questions.

Leave a Reply