Install mysql as a shell

I have a user on my machine that should only run mysql. Is there a way that I can install this user shell in mysql and login using password and username?

I know how to change shell to mysql binary

usermod -s /usr/bin/mysql 

This really works, only I can not specify the username / password in the program. Usually user / pw is indicated as

 mysql -u $USER -p 

I can not provide options for the shell, as in

 usermod -s "/usr/bin/mysql -u $USER -p" # Does not work! 

Also using a simple shell script as a shell does not work:

 #!/bin/sh # mysqlShell /usr/bin/mysql -u $USER -p ---- usermod -s mysqlShell # does not work 

So, how can I provide parameters for the program that I use as a shell for the user?


Thanks to Tom Regner, I could find a solution using .my.cnf containing

 [client] host=localhost user=$user password=$pass disable-auto-rehash 

where mysql is installed in the shell. I would still like to give the password manually, but this is the best I have found.

+4
source share
3 answers

Configure $HOME/.my.cnf for the user

 [client] host=localhost user=mysqluser password=mysqlpass 

then set bash as your login shell and put the following in $HOME/.bashrc

 exec mysql --host=localhost dbname 

which should do what you want, while the user in question just has to specify one password (the password of the system account when logging in).

exec replaces the shell process with the mysql process.

If this does not work properly, you may need to configure $HOME/.bash_profile to source .bashrc :

 [[ -f ~/.bashrc ]] && . ~/.bashrc 

It is enough to specify the appropriate .my.cnf and set /usr/bin/mysql as a shell, but in this way you can pass arbitrary parameters / command line flags for the mysql client.

+2
source

This can be done by editing the user account information in the / etc / passwd file and changing the default shell.

+1
source

You need a password to log in (if you have not configured ssh accordingly). Use the following command: sudo passwd username to change this login password.

You also need mysql password. Use SET PASSWORD Mysql Query.

If you want the user to be connected to some fixed database with some fixed password, enter a small C-shell (then make the executable executable only by your Unix user) by executing mysql_real_connect or by calling the exec function for mysql --user= username --password= password_data_name, but I do not recommend doing this later (because ps aux will show a password, and this is a security risk).

Perhaps, since MySQL is free software, you can customize the mysql source code for your specific needs.

Perhaps using a limited shell and fine-tune it better.

+1
source

Source: https://habr.com/ru/post/1482527/


All Articles