ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
In Linux, each user you create using useradd has a home direcotry, something like /home/user.
In /etc/passwd there is an "apache" user.
I am running Apache and when the user enters a number in a web page in the browser, a CGI script (Perl) is executed and this is supposed to scp a file from a remote server.
But if I cannot su apache, how can I scp the file. I need to create the private and public keys.
What do you mean by "I cannot su apache"? As root you should be
able to do that; of course if nobody has a shell of false the
login won't last long ...
I don't fully understand why you want to run an scp from a cgi-script, I would suggest that you be sure to have signifcant security in place for this task.
The web server should already be running as the apache user, so you do not need to su to apache. You can use the -i option with scp (and ssh) to point to the private key. If you generate your keys and then put the private key in a safe place that the user of the web server (apache) can access, then point to that file in your cgi script using the -i option, it should be able to copy the necessary files.
Last edited by rlhartmann; 05-10-2008 at 10:14 PM.
Reason: Corrected grammar
Thanks for suggesting the -i option. Let me try that out.
The story goes like this: A user has an ID which corresponds to the name of a text file in server 1.
Another server 2 running Apache, provides a web page for the user to enter the ID, and this triggers a script to copy that text file from the remote server, and then process it.
So, the user Apache needs to secure copy the file without entering passwords and then process it.
...You can use the -i option with scp (and ssh) to point to the private key. If you generate your keys and then put the private key in a safe place that the user of the web server (apache) can access, then point to that file in your cgi script using the -i option, it should be able to copy the necessary files.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.