<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: How to Run &#8216;sudo&#8217; Command Without Entering a Password in Linux	</title>
	<atom:link href="https://www.tecmint.com/run-sudo-command-without-password-linux/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.tecmint.com/run-sudo-command-without-password-linux/</link>
	<description>Tecmint - Linux Howtos, Tutorials, Guides, News, Tips and Tricks.</description>
	<lastBuildDate>Mon, 14 Oct 2024 04:27:38 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>
		By: Trevor Chandler		</title>
		<link>https://www.tecmint.com/run-sudo-command-without-password-linux/comment-page-1/#comment-2227959</link>

		<dc:creator><![CDATA[Trevor Chandler]]></dc:creator>
		<pubDate>Mon, 14 Oct 2024 04:27:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.tecmint.com/?p=24302#comment-2227959</guid>

					<description><![CDATA[Succinct and straightforward - my type of article!]]></description>
			<content:encoded><![CDATA[<p>Succinct and straightforward &#8211; my type of article!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Nitin		</title>
		<link>https://www.tecmint.com/run-sudo-command-without-password-linux/comment-page-1/#comment-1472946</link>

		<dc:creator><![CDATA[Nitin]]></dc:creator>
		<pubDate>Thu, 08 Apr 2021 15:34:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.tecmint.com/?p=24302#comment-1472946</guid>

					<description><![CDATA[In response to the question asked here: https://stackoverflow.com/questions/25189348/unable-to-provide-password-to-a-process-with-subprocess-python

On Linux you can bypass the sudo prompt using:
&lt;pre&gt;
````bash
echo  &#124; sudo -S whoami
````
&lt;/pre&gt;
Pass the formatted command to subprocess and you are good to go:
&lt;pre&gt;
````python
import subprocess as sp

cmd = &quot;whoami&quot;
password= &quot;&quot;

stdout, stderr = sp.Popen(&quot;echo {} &#124; sudo -S {}&quot;.format(password, cmd), shell=True, stdout=sp.PIPE, stderr=sp.PIPE).communicate()

print(stdout.decode())

if stderr:
    print(&quot;error occured:&quot;)
    print(stderr.decode())
````
&lt;/pre&gt;
It should print `root` as the command is executed by the sudo user.]]></description>
			<content:encoded><![CDATA[<p>In response to the question asked here: <a target="_blank" href="https://stackoverflow.com/questions/25189348/unable-to-provide-password-to-a-process-with-subprocess-python" rel="nofollow ugc">https://stackoverflow.com/questions/25189348/unable-to-provide-password-to-a-process-with-subprocess-python</a></p>
<p>On Linux you can bypass the sudo prompt using:</p>
<pre>
````bash
echo  | sudo -S whoami
````
</pre>
<p>Pass the formatted command to subprocess and you are good to go:</p>
<pre>
````python
import subprocess as sp

cmd = "whoami"
password= ""

stdout, stderr = sp.Popen("echo {} | sudo -S {}".format(password, cmd), shell=True, stdout=sp.PIPE, stderr=sp.PIPE).communicate()

print(stdout.decode())

if stderr:
    print("error occured:")
    print(stderr.decode())
````
</pre>
<p>It should print `root` as the command is executed by the sudo user.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Madhusudhan Kasula		</title>
		<link>https://www.tecmint.com/run-sudo-command-without-password-linux/comment-page-1/#comment-1316652</link>

		<dc:creator><![CDATA[Madhusudhan Kasula]]></dc:creator>
		<pubDate>Fri, 14 Feb 2020 15:09:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.tecmint.com/?p=24302#comment-1316652</guid>

					<description><![CDATA[Alternately you can use python pudo package: &lt;strong&gt;https://pypi.org/project/pudo/1.0.0/&lt;/strong&gt;

Installation:
&lt;pre&gt;
$ sudo -H pip3 install pudo # you can install using pip2 also
&lt;/pre&gt;
Below is the code snippet for using in python automation for running commands under root privilege::
&lt;pre&gt;
    user$ python3 # or python2
    &#062;&#062;&#062; import pudo
    &#062;&#062;&#062; (ret, out) = pudo.run((&#039;ls&#039;, &#039;/root&#039;)) # or pudo.run(&#039;ls /root&#039;)
    &#062;&#062;&#062; print(ret)
    &#062;&#062;&#062; 0
    &#062;&#062;&#062; print(out)
    &#062;&#062;&#062; b&#039;Desktop\nDownloads\nPictures\nMusic\n&#039;
&lt;/pre&gt;
Below is the cmd example for running commands under root privilege
&lt;pre&gt;
    user$ pudo ls /root
    Desktop  Downloads  Pictures  Music
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Alternately you can use python pudo package: <strong><a target="_blank" href="https://pypi.org/project/pudo/1.0.0/" rel="nofollow ugc">https://pypi.org/project/pudo/1.0.0/</a></strong></p>
<p>Installation:</p>
<pre>
$ sudo -H pip3 install pudo # you can install using pip2 also
</pre>
<p>Below is the code snippet for using in python automation for running commands under root privilege::</p>
<pre>
    user$ python3 # or python2
    &gt;&gt;&gt; import pudo
    &gt;&gt;&gt; (ret, out) = pudo.run(('ls', '/root')) # or pudo.run('ls /root')
    &gt;&gt;&gt; print(ret)
    &gt;&gt;&gt; 0
    &gt;&gt;&gt; print(out)
    &gt;&gt;&gt; b'Desktop\nDownloads\nPictures\nMusic\n'
</pre>
<p>Below is the cmd example for running commands under root privilege</p>
<pre>
    user$ pudo ls /root
    Desktop  Downloads  Pictures  Music
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Aaron Kili		</title>
		<link>https://www.tecmint.com/run-sudo-command-without-password-linux/comment-page-1/#comment-875892</link>

		<dc:creator><![CDATA[Aaron Kili]]></dc:creator>
		<pubDate>Wed, 15 Mar 2017 21:30:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.tecmint.com/?p=24302#comment-875892</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.tecmint.com/run-sudo-command-without-password-linux/comment-page-1/#comment-875788&quot;&gt;Hubo&lt;/a&gt;.

@Hubo

Yap, according to the sudoers man page, which explains that, &quot;Multiple users and groups may be present in a Runas_Spec(run as user or group), in which case the user may select any combination of users and groups.

In this example:

 &lt;strong&gt;aaronkilik    ALL = (root, bin : operator, system) ALL&lt;/strong&gt;

The user  aaronkilik  may run any command as either user root or bin, optionally setting the group to operator or system. &quot;

For additional info, go through the sudoers man page:
&lt;strong&gt;man sudoers&lt;/strong&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a target="_blank" href="https://www.tecmint.com/run-sudo-command-without-password-linux/comment-page-1/#comment-875788">Hubo</a>.</p>
<p>@Hubo</p>
<p>Yap, according to the sudoers man page, which explains that, &#8220;Multiple users and groups may be present in a Runas_Spec(run as user or group), in which case the user may select any combination of users and groups.</p>
<p>In this example:</p>
<p> <strong>aaronkilik    ALL = (root, bin : operator, system) ALL</strong></p>
<p>The user  aaronkilik  may run any command as either user root or bin, optionally setting the group to operator or system. &#8221;</p>
<p>For additional info, go through the sudoers man page:<br />
<strong>man sudoers</strong></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Hubo		</title>
		<link>https://www.tecmint.com/run-sudo-command-without-password-linux/comment-page-1/#comment-875788</link>

		<dc:creator><![CDATA[Hubo]]></dc:creator>
		<pubDate>Wed, 15 Mar 2017 10:32:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.tecmint.com/?p=24302#comment-875788</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.tecmint.com/run-sudo-command-without-password-linux/comment-page-1/#comment-875782&quot;&gt;Hubo&lt;/a&gt;.

Sorry,  some mistakes have occured,  the syntax to add a record , for example, &quot;root ALL=(user1, user2: group1, group2) NOPASSWD:  ALL&quot;,  is it right, Thanks.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a target="_blank" href="https://www.tecmint.com/run-sudo-command-without-password-linux/comment-page-1/#comment-875782">Hubo</a>.</p>
<p>Sorry,  some mistakes have occured,  the syntax to add a record , for example, &#8220;root ALL=(user1, user2: group1, group2) NOPASSWD:  ALL&#8221;,  is it right, Thanks.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
