LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-01-2012, 11:53 AM   #1
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Rep: Reputation: 0
Running a process as apache, change to root ?


Hello,

I have an SVN server that should with the post-commit script loginto our dev server via ssh and update the folders contianing the websites.

However, because the post-commit scripts runs as 'apache', it has no rights to run the ssh command.

Can someone help me with this. It would be greatly appreciated. Thanks in advance.
 
Old 02-01-2012, 03:25 PM   #2
rustek
Member
 
Registered: Jan 2010
Location: Melbourne, IA, USA
Distribution: Ubuntu
Posts: 93

Rep: Reputation: 8
You said "websites" plural, and that scares me.
If you have client websites running cgi scripts as the user apache then what I am about to suggest is probably a Bad idea.

But if you use suexe and each website runs their cgi scripts as their own user then this will work safely.

visudo and add the line;
Code:
apache ALL=(root) NOPASSWD: /usr/bin/ssh
Then in your post-commit script change the "ssh" command to "sudo ssh" and this should do the trick.

It would probably be better to find out why the user apache can't run ssh, if the user needs to be in a certain group, then discover that and place apache in that group.

Again, I would be careful giving rights to the user apache if there are other users running cgi as the user apache.

Last edited by rustek; 02-01-2012 at 03:37 PM.
 
Old 02-01-2012, 04:28 PM   #3
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rustek View Post
You said "websites" plural, and that scares me.
If you have client websites running cgi scripts as the user apache then what I am about to suggest is probably a Bad idea.

But if you use suexe and each website runs their cgi scripts as their own user then this will work safely.

visudo and add the line;
Code:
apache ALL=(root) NOPASSWD: /usr/bin/ssh
Then in your post-commit script change the "ssh" command to "sudo ssh" and this should do the trick.

It would probably be better to find out why the user apache can't run ssh, if the user needs to be in a certain group, then discover that and place apache in that group.

Again, I would be careful giving rights to the user apache if there are other users running cgi as the user apache.
Well that worked. Thank you very much !!! I can at least get the team back working. I know it is bad practice, I will troubleshoot how come apache couldn't login. Maybe I should create a user that will do this. Thank again. Note: it worked without the sudo.

Last edited by rbalaa; 02-01-2012 at 04:32 PM.
 
Old 02-01-2012, 04:30 PM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
I hope you sanitize your inputs (web form etc) !
 
Old 02-01-2012, 05:33 PM   #5
rustek
Member
 
Registered: Jan 2010
Location: Melbourne, IA, USA
Distribution: Ubuntu
Posts: 93

Rep: Reputation: 8
Quote:
Note: it worked without the sudo.
It would not have worked on my systems without the sudo, yours may behave differently or your problem may have magically gone away?
 
Old 02-01-2012, 05:55 PM   #6
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Why the need to run ssh as root anyway, is there any theory behind this ?
 
Old 02-01-2012, 06:23 PM   #7
rustek
Member
 
Registered: Jan 2010
Location: Melbourne, IA, USA
Distribution: Ubuntu
Posts: 93

Rep: Reputation: 8
Quote:
Originally Posted by Cedrik View Post
Why the need to run ssh as root anyway, is there any theory behind this ?
He may be copying files with various owners and various permissions to the other box, so my answer to you is yes.

If your are going to help, then help, otherwise...
 
Old 02-01-2012, 06:41 PM   #8
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by rustek View Post
If your are going to help, then help, otherwise...
I would like to help, but before I have to fully understand the issue

ssh is a program for login into a remote machine, it is like ftp but with encrypted connection...

It requires no root privileges to use it

Quote:
Originally Posted by rustek View Post
He may be copying files with various owners and various permissions to the other box, so my answer to you is yes.
If I have password for an user in a remote ssh server, I can login without being that user
And any file I copy with ssh will belong to the remote user...

Anyway, in the end rbalaa succeed using ssh without using sudo (= without having root privileges), so the issue is elsewhere

Last edited by Cedrik; 02-01-2012 at 06:42 PM.
 
Old 02-01-2012, 08:06 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by rustek View Post
If your are going to help, then help, otherwise...
Please be aware that asking questions is often the best way to start troubleshooting things or having something clarified. Asking prudent questions should never be met with such a reply. And I fully agree one should question having a non-human account run anything as root, especially if "it worked before without Sudo" which could point to misconfiguration on the OPs part.
 
Old 02-01-2012, 08:26 PM   #10
rustek
Member
 
Registered: Jan 2010
Location: Melbourne, IA, USA
Distribution: Ubuntu
Posts: 93

Rep: Reputation: 8
My first commercial Linux system was RedHat Mothers Day, If you don't want me here that's fine.
 
Old 02-01-2012, 09:04 PM   #11
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Original Poster
Rep: Reputation: 0
Still not working. Don't ask me why, but it worked for sometime, and now its back. Anyhow you are right I should have explained the setup better. Yes, I wanted to SSH so that I can update our live server. Now after many frustrated hours, I decided to have both SVN and our live server on the same box.
I found a debug script online and this is what I get when post-commit runs:


/svndata/live 95
uid=48(apache) gid=48(apache) groups=0(root),48(apache)
PWD=/
SHLVL=1
_=/bin/env


As opposed to when I run it manually, I get:


uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
HOSTNAME=msrv01
SHELL=/bin/bash
TERM=xterm-256color
HISTSIZE=1000
SSH_CLIENT=<ipadress>
SSH_TTY=/dev/pts/1
USER=root
LS_COLORS=
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/scripts
MAIL=/var/spool/mail/root
PWD=/svndata/live/hooks
INPUTRC=/etc/inputrc
LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
HOME=/root
SHLVL=2
LOGNAME=root
SSH_CONNECTION=<ipaddress>
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env

the debug code is:

date >> /tmp/debug.txt
echo "$@" >> /tmp/debug.txt
id >> /tmp/debug.txt
env >> /tmp/debug.txt

Please help. Thank you.
 
Old 02-02-2012, 01:56 AM   #12
rbalaa
Member
 
Registered: Mar 2010
Posts: 61

Original Poster
Rep: Reputation: 0
well mark it as solved. the reason my connection kept breaking is because I never once listed my SVN repo from the local server (where svn is located). Soon as I did that, it asked me to accept (p). So I did and now it works. I also forgot to mention that the SVN server is running with HTTPS.

Thanks All.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can we change cpu utilization of running process sandeep002gupta Linux - General 1 04-28-2011 06:11 AM
How to change a process running in root-user to non-root user ???????????????????? narendra1310 Linux - Software 4 10-29-2009 02:11 AM
How can i change the priority of a running process. ZAMO Linux - Enterprise 3 04-23-2007 03:31 AM
running a process when a directory or its contents change stevenk15 Linux - Software 1 12-27-2005 11:44 AM
Change the display of a running process? ejkeebler Linux - Newbie 3 06-16-2004 08:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration