think tank forum

technology » sudo question

lucas's avatar
15 years ago
r2, link
lucas
i ❤ demo
is it possible to run commands like this with sudo?

echo "ssh-rsa AAAAAAAA=" > /home/larz/.ssh/authorized_keys

the part of the command that needs sudo isn't the echo, but writing it to the file in another user's directory. as a result, this doesn't work:

% sudo echo "ssh-rsa AAAAAAAA=" > /home/larz/.ssh/authorized_keys
[zsh: permission denied: /home/larz/.ssh/authorized_keys]

thanks!

--

bsdnexus cross-post
andre's avatar
15 years ago
link
andre
I'm not sure if you can do that directly, but if you put the command in a shell script and give it execute permissions, you should be able to add that to the sudoers file.
lucas's avatar
15 years ago
link
lucas
i ❤ demo
roddierod on bsdnexus gave a good solution, too. thanks.
Carpetsmoker's avatar
15 years ago
link
Carpetsmoker
Martin
sudo su?
andre's avatar
15 years ago
link
andre
What was the solution?
lucas's avatar
15 years ago
link
lucas
i ❤ demo
i just wanted a quick one-liner for the cli.

he gave this, but it's a bit longer than my ideal solution:

sudo sh -c 'echo "ssh-rsa AAAAAA=" > /home/larz/.ssh/authorized_keys'
andre's avatar
15 years ago
link
andre
Ah, now I understood what you meant... Most times I just do "sudo -s" and get a shell :P