Skip to Content

List user and subssh user mapped

How to list the usernames and the corresponding subssh users mapped individually?

1. Find the database and table name using the below command.

root@gateway ~]# cat /usr/local/etc/ezlogin/ez.conf | grep -i "db_name\|db_prefix"

db_name ezlogin_wupluh
db_prefix btu_

2. Login to the MySQL server and run the query below to list the usernames and the corresponding subssh users mapped individually from the user edit.

root@gateway ~]# mysql -u root -p

Enter password:

mysql> use ezlogin_wupluh;

mysql> select u.username as user, s.username as sub_ssh_user from btu_users as u join btu_ssh_users as s on u.ssh_user_id = s.id;

+--------+--------------+
| user   | sub_ssh_user |
+--------+--------------+
| alex   | john         |
| tony   | nick         |
+--------+--------------+
2 rows in set (0.00 sec)

Execute the following command and provide the MySQL root password when prompted to get the list with a single command.

root@gateway ~]# mysql -u root -p -e "USE $(grep -oP 'db_name\s+\K\S+' /usr/local/etc/ezlogin/ez.conf);select u.username as user, s.username as sub_ssh_user from $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)users as u join $(grep -oP 'db_prefix\s+\K\S+' /usr/local/etc/ezlogin/ez.conf)ssh_users as s on u.ssh_user_id = s.id;"

Enter password:

+--------+--------------+
| user   | sub_ssh_user |
+--------+--------------+
| alex   | john         |
| tony   | nick         |
+--------+--------------+