AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Sudo su run command11/23/2023 ![]() In your script (on your local computer) you now can call Now to check if all went well just try ssh If this works without being asked for a password your done. Next, for every server involved call ssh-copy you will be asked for the password of s_user on the server. This will be stored in ~/.ssh directory by default. I suppose you know the password for s_user on every server, and there is sshd installed on those servers (and works as expected depends on what OS runs on the servers).Īs mpromonet stated, you may use ssh, but without logging into the servers with your own credentials.įirst, generate your own key pair with ssh-keygen. This is not exactly the answer to your question, but could be a solution for your task. sudo does not read password from stdin, it reads from tty.sudo, by default, takes the password of the user you are (you are switching from).su takes the password of the user that you are switching to.Then set up a shell alias, something like: alias s_command="sudo -u s_user command". This will allow password less use of those commands, as s_user, but only for users in group s_group (you will have to add the group). %s_group ALL = (s_user) NOPASSWD : S_COMMAND However you can now configure /etc/sudoersĪdd a file /etc/sudoers.d/s_commands, containing something like (but checked, with /usr/bin/visudo): Cmnd_Alias S_COMMAND=/usr/bin/command, /usr/bin/anotherCommand You will still be asked for your password. So instead of sudo su - s_user -c command, do sudo -u s_user command. You could do it by instead adding your ssh key to the s_user account, but I think this solution in this case is sub-optimal.įirst I will point out that you don't need su, and it is best not to use it. To do this you will use your password (for sudo). I see you are using sudo to become root, and then su to become s_user. I cannot use “expect”, it’s not installed in my machines.The above command still ask for the password. echo password|sudo -S su - user-to-switch I am able to run the command successfully. su -c "command_to_restart_the_services" -s /bin/sh abc.xyz echo 'my password'|su -c "./bin/services stop" -s /bin/sh abc.xyz echo 'password'|sudo -S su - s_user -c "./bin/service stop" I have provided s_user in the below command, but still I am getting the same output error as 1st command. I replaced ‘su’ with ‘u’ in the below command, but still I am getting the same output error as 1st command. ![]() I have also tried giving the s_user password but it gives below output: password for abc.xyz: Sorry,try again. ![]() Password for abc.xyz: Sorry, user abc.xyz is not allowed to execute '/bin/su - s_user' -c /bin/services stop' as root on The following commands I have tried so far: 1. I want to skip the password prompt by supplying the password to su through stdin. This procedure I have to do in all the servers. The above command prompts for password where I will provide my password to restart services. To Run the Restart service I need to switch user to s_user using below command: ( I need this command without password prompt) sudo su - s_user Login to server with my username and password.I as a normal user do not have rights to run services restart commands. I am writing a shell script where I want to automate service Restart process on multiple Unix servers.
0 Comments
Read More
Leave a Reply. |