Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 1202  / 1 Year ago, sat, january 21, 2023, 3:48:21

I generally run sudo mysql database < database.dump and type the password on prompt.



In order to automate this, I tried to execute echo 'password' | sudo -S mysql database < database.dump but it is not recognizing my password.



I can sudo -S other commands normally. What might be the problem?


More From » sudo

 Answers
5

No you do not



If you need to do something like this as root, please do it properly.




  • Create a new script in /usr/local/bin/ like /usr/local/bin/my_mysql_task. It'll need to be owned by root and chmod +xed. The important thing here is that nobody but root can edit it.

  • Then let your user run that script as root without a password by running sudo visudo and adding something like the following:



    username   ALL=NOPASSWD: /usr/local/bin/my_mysql_task



Now are you not only not piping your account password everywhere (in a way that would show in ps to most other users) but you're not piping at all, thus solving your core issue.



Never embed passwords. It's not necessary.


[#28741] Saturday, January 21, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
egantfis

Total Points: 406
Total Questions: 108
Total Answers: 108

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
;