Why does sudo not work with curl?

10

1

I ran a command to download something with curl

sudo curl roots.cx/get | sh

– and it threw a permission denied error. So I did sudo curl and I got the same error … why is that?

I was able to run the install command without curl, but I needed to sudo, so why does curl not work with sudo?

GiH

Posted 2013-02-13T05:11:26.883

Reputation: 3 667

3Can you show the full command ? – Ofiris – 2013-02-13T05:28:58.680

Are you sure the website was not returning the "permission denied" error, rather then Perl ? What variant of Linux are you using and is SELinux running ? – davidgo – 2013-02-13T05:44:26.437

@davidgo I'm using OS X for this... – GiH – 2013-02-13T15:44:29.117

@Ofiris sudo curl roots.cx/get | sh – GiH – 2013-02-13T15:45:37.043

@GiH Try adding a sudo after the pipe – Ofiris – 2013-02-13T17:03:42.090

@Ofiris Thanks that worked! Care to put an answer to the question for why? I don't fully understand why the initial command doesn't work with sudo, but once it is piped it does... just to be clear to anyone who reads this it worked with curl roots.cx/get | sudo sh – GiH – 2013-02-13T18:00:23.300

@GiH , posted as an answer, will add details soon. – Ofiris – 2013-02-13T19:58:41.910

Answers

5

Use sudo after the pipe:

curl roots.cx/get | sudo sh

the get script involves some installation, requires sudo to run.

Ofiris

Posted 2013-02-13T05:11:26.883

Reputation: 1 623

Not working on OS X 10.10.3. – Ain – 2015-04-16T17:25:48.303

@Ain in Super User, consider the popular answer to Redirect output to a file permission denied? (2013-05-15).

– Graham Perrin – 2017-03-23T05:16:26.697

2

Alternatively you can use:

sudo \curl roots.cx/get | sh

Eric Semwenda

Posted 2013-02-13T05:11:26.883

Reputation: 121