how do I can achieve sudo privilege via the shell script without entering the password? Example:   [user@user Desktop]$ ./script.sh  [user@user Desktop]#    which command should I try on the script.sh? I do not want to add in the sudoers file. Please help me. Thanks for your valuable time.
121067
I have a script which can run as sudo script.sh or pkexec script.sh  It would be much nicer from the user point of view if the script asked for the password from the user when just running it by name script.sh.   How can I "embed" request to pkexec or sudo to run the whole script with root privilege?  Note that running everything with sudo sh -c might not be the best solution as I have functions in the script.
77228
when I try using a command with sudo everything works fine, however, if I want to log in as the superuser using su it doesn't let me. Why?
23604
I tried writing a shell script which can do automatic login into a ssh server using password which is mentioned in the script. I have written the following code:  set timeout 30 /usr/bin/ssh -p 8484 root@172.31.72.103 expect  {    "root@172.31.72.103's password"     {       send "password\r"     } }   This code is not running properly, still it is asking for the password. Can somebody please help me in solving this
67372
Why  do we use sudo to perform a terminal command as an administrative? Why isn't it  admin or something else? Is there a reason for sudo?
99605
[root@notebook ~]# grep root /etc/sudoers root    ALL=(ALL)   ALL   Question: Why does the root user need sudo permissions? I've seen it on different UNIX OSes. Can someone please explain this?
53147
I don't need an administrator to change my root password. I don't want any sudo user to execute this command:  sudo passwd $root   I have tried it in the sudoers file using the following command:  %sudo ALL=(ALL) ALL, !/usr/bin/passwd $root   How can I block it?
89927
We have several user accounts that we create for automated tasks that require fine-grained permissions, such as file transfer across systems, monitoring, etc.   How do we lock down these user accounts so that these "users" have no shell and are not able to login? We want to prevent the possibility that someone can SSH in as one of these user accounts.
19639
Is it possible to execute a script if there is no permission to read it? In root mode, I made a script and I want the other user to execute this script but not read it. I did chmod to forbid read and write but allow execute, however in user mode, I saw the message that says: permission denied.
776
When I'm about to install a program in the terminal it wants the password:  [sudo] password for xxx:   But when I start to type my password nothing happens. What should I do?
123757
I have a script run from a non-privileged users' crontab that invokes some commands using sudo. Except it doesn't. The script runs fine but the sudo'ed commands silently fail.   The script runs perfectly from a shell as the user in question. Sudo does not require a password. The user in question has (root) NOPASSWD: ALL access granted in /etc/sudoers. Cron is running and executing the script. Adding a simple date &gt; /tmp/log produces output at the right time. It's not a permissions problem. Again the script does get executed, just not the sudo'ed commands. It's not a path problem. Running env from inside the script being run shows the correct $PATH variable that includes the path to sudo. Running it using a full path doesn't help. The command being executed is being given the full path name. Trying to capture the output of the sudo command including STDERR doesn't show anything useful. Adding sudo echo test 2&gt;&amp;1 &gt; /tmp/log to the script produces a blank log. The sudo binary itself executes fine and recognizes that it has permissions even when run from cron inside the script. Adding sudo -l &gt; /tmp/log to the script produces the output:       User ec2-user may run the following commands on this host:   (root) NOPASSWD: ALL    Examining the exit code of the command using $? shows it is returning an error (exit code: 1), but no error seems to be produced. A command as simple as /usr/bin/sudo /bin/echo test returns the same error code.  What else could be going on?  This is a recently created virtual machine running the latest Amazon Linux AMI. The crontab belongs to the user ec2-user and the sudoers file is the distribution default.
63129
The purpose is to restart the machine if it doesn't get an abort command from the user. The problem is that the way the terminals are set up, user must supply SU password for shutdown, init, reboot, etc. commands. We are wondering if it's possible to supply password in bash script itself, maybe using stdin. i.e.:  #!/bin/bash # (script) echo "Terminal will restart in 60s, Ctrl+C to cancel." sleep 60 su - root -c "init 6" &lt; "password"   We are going to try putting the password in a file and stdin that.  Edit: sudo and expect are out as solutions as getting them installed will be impossible due to a massive amount of paperwork for permission and a limited timeframe. Also we would like to use init 6 or shutdown -r rather than reboot.
58568
I am trying to make a script like this:  #!/bin/bash sudo -s something...   When I execute it, I get a new shell but something is executed only when I exit the shell created by sudo -s, not inside it.  Any help?
36380
On busy days, I'd like to run   $ ./configure &amp;&amp; make &amp;&amp; sudo make install &amp;&amp; halt   on the night and go to bed, hoping the application would automatically be installed. But what I see the next day is the screen where sudo asks me for the password. So how could I run sudo with password in one command line, or is there any other method to do this?
88610
$ ls -l /usr/bin/sudo -rwsr-xr-x 1 root root 136808 Jul  4  2017 /usr/bin/sudo   so sudo is runnable by any user, and any user who runs sudo will have root as the effective user ID of the process because the set-user-id bit of /usr/bin/sudo is set.  From      the most visible difference between sudo and su is that sudo requires the user's password and su requires root's password.    Which user's password does sudo asks for? Is it the user represented by the real user ID of the process?   If yes, doesn't any user can gain the superuser privilege by running sudo and then providing their own password? Can Linux restrict that on some users? Is it correct thatsudo asks for the password after execve() starts to execute main() of /usr/bin/sudo?  Since the euid of the process has been changed to root (because the set-user-id bit of /usr/bin/sudo is set), what is the point of sudo asking for password later?   Thanks.  I have read , but it doesn't answer the questions above.
47205
I'm running a remote bash script (using ssh -t 'bash doscript.sh'). In "doscript.sh" I have a sudo su anotheruser. At that point, the script seems to push a shell and I'm left in that "interactive" script and the rest of my script (doscript.sh) doesn't run unless I type "exit". Is there a workaround that gets around this problem?  Thanks in advance.  Here is the contents of my test script "doscript.sh":  sudo su diy cd pwd whoami exit whoami
124201
I would like to run vagrant without being prompted for a password. As this post suggests, I used visudo to add the following line to my sudoers file.  john-moz ALL=(ALL) NOPASSWD: /usr/bin/vagrant   This does not seem to work. I am still prompted for a password when using vagrant. Am I doing something wrong?
116442
Frequently in Terminal (though I fully expect any answer will work in bash and most others), I type some command, and then get some sort of permission error due to missing sudo.  Okay, so press 'up', hold/hammer 'left', type sudo and hit 'enter'.  It's annoying. More so the longer the command was.  Note that missing sudo is worst case; a typo nearer the beginning than end is similarly annoying.  What I would like, is a way to perform a sort of 'up and home' keystroke. Actually, perhaps those two strokes will do it - but my Macbook keyboard doesn't have Home, so I cannot try.  Bonus points for a way to insert sudo and hit 'enter' auto-magically too, say by CMD+Shift+S.    Can this be done, or am I dreaming?