i will create file sh (bash script)
#!/bin/bash
su - username -c XXXXXXXX
xxxxxx= command
where i put my password?( but NOT ask me password in terminal..how?)
You should look into properly setting up your sudoers
file. You would do this with a program called visudo
, which does some behind-the-scenes magic.
sudoers
can be set up in a way such that any user can be given access to a limited set or all commands available on the system. You can also set it up so that a user can run any command as another user. I think this third method is the way you'll decide to go.
However, If you've decided this is something you truly want to accomplish, I would recommend determining what commands you want to run, and use the whitelist approach, vs unlocking all commands.
If you're running Chromium, or Firefox, or any server/client exposed to the Internet as a user in the sudoers file with unfettered, password-less access, you might as well be running them under root.
visudo
user1@host $ sudo -u user2 cat /home/user2/.ssh/authorized_keys
Resources:
visudo
. Read about sudoers
.
Jun 22, 2015 at 16:54
sudo su
might be a better solution. (And sudo can be configured to work passwordless for certain commands).