Sunday, July 14, 2024

.::: Create User Access MariaDB MySQL using PAM example OS Linux Login :::.

 
1. install pam plugin

INSTALL PLUGIN pam SONAME 'auth_pam';

MariaDB [(none)]> INSTALL PLUGIN pam SONAME 'auth_pam';
ERROR 1968 (HY000): Plugin 'pam' already installed
MariaDB [(none)]>


2. check plugin pam

show plugins
SELECT plugin_name,plugin_version,plugin_status,plugin_type,plugin_library,plugin_author FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE '%pam%';
 


3. add pam config
[root@teguhth ~]# cat /etc/pam.d/mariadb
auth required pam_unix.so audit
account required pam_unix.so audit
[root@teguhth ~]#


4. create user OS in linux

[root@teguhth ~]# useradd noc
[root@teguhth ~]# passwd noc
Changing password for user noc.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@teguhth ~]#
[root@teguhth ~]# cat /etc/passwd | grep -i noc
noc:x:1000:1000::/home/noc:/bin/bash
[root@teguhth ~]#
 

5. create user pam

CREATE USER 'noc'@'%' IDENTIFIED VIA pam USING 'mariadb';
GRANT ALL PRIVILEGES ON *.* TO 'noc'@'%';
FLUSH PRIVILEGES;


6. test login
mysql -hlocalhost -unoc -p

SELECT @@hostname AS Hostname,USER,HOST,PLUGIN,authentication_string FROM mysql.user;

 



No comments:

Post a Comment

Popular Posts