Here’s how to set up a sqladmin user with administrative privileges in Debian for common database systems (MySQL/PostgreSQL/SQL Server):
First, install your chosen database (replace with your preferred system):
sudo apt update && sudo apt install mysql-server -y
sudo apt update && sudo apt install postgresql postgresql-contrib -y
sudo apt update && sudo apt install -y curl gnupg apt-transport-https
curl https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/debian/$(lsb_release -cs)/prod stable main" | sudo tee /etc/apt/sources.list.d/mssql-server.list
sudo apt update && sudo apt install -y mssql-server
sudo /opt/mssql/bin/mssql-conf setup # Set SA password during setup
sqladmin
User with Admin PrivilegesConnect to MySQL as root and execute:
CREATE USER 'sqladmin'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON *.* TO 'sqladmin'@'localhost' WITH GRANT OPTION; -- Full admin rights
FLUSH PRIVILEGES; -- Apply changes immediately
Switch to the postgres
user (default admin) and run:
sudo -u postgres psql
Then, in the PostgreSQL shell:
CREATE USER sqladmin WITH PASSWORD 'StrongPassword123!';
ALTER ROLE sqladmin WITH SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN; -- Superuser rights
\q -- Exit the shell
Connect via sqlcmd
(or SSMS) and execute:
CREATE LOGIN sqladmin WITH PASSWORD = 'StrongPassword123!';
ALTER SERVER ROLE sysadmin ADD MEMBER sqladmin; -- Add to sysadmin role (full control)
For database-specific admin rights, also run:
USE YourDatabaseName;
CREATE USER sqladmin FOR LOGIN sqladmin;
ALTER ROLE db_owner ADD MEMBER sqladmin; -- Owner of the database
Edit the MySQL config file (/etc/mysql/mysql.conf.d/mysqld.cnf
) and change:
bind-address = 0.0.0.0 # Allow connections from all IPs (adjust for security)
Restart MySQL:
sudo systemctl restart mysql
Edit the PostgreSQL config file (/etc/postgresql/<version>/main/postgresql.conf
):
listen_addresses = '*' # Allow all IPs (or specify a subnet)
Update pg_hba.conf
(/etc/postgresql/<version>/main/pg_hba.conf
) to allow sqladmin
access:
host all sqladmin 0.0.0.0/0 md5 # MD5 password auth
Restart PostgreSQL:
sudo systemctl restart postgresql
Edit the SQL Server config file (/etc/opt/mssql/mssql.conf
) and set:
[network]
tcpip = true # Enable TCP/IP
Restart SQL Server:
sudo systemctl restart mssql-server
Open firewall port 1433 (SQL Server default):
sudo ufw allow 1433/tcp
sqladmin
Accountbind-address
/listen_addresses
to trusted IPs (e.g., 192.168.1.0/24
).REQUIRE SSL
, SQL Server’s certificate settings).audit_log
, SQL Server’s Audit feature).sqladmin
AccountConnect to the database using the sqladmin
credentials to confirm access:
mysql -u sqladmin -p
psql -U sqladmin -d postgres
sqlcmd -S localhost -U sqladmin -P StrongPassword123!
Enter the password when prompted. If connected successfully, the sqladmin
user has the correct privileges.
This process ensures you have a secure, functional sqladmin
user for managing your Debian-based database system. Adjust steps based on your specific database (MySQL/PostgreSQL/SQL Server) and security requirements.