Solved

changing user for command

Posted on 2004-09-10
4
241 Views
Last Modified: 2012-05-05

Hello.

I want to log in with SSH as "webuser" but I want to do the following:

     cp -pr /home/web/mysite.com/html/source /home/web/mysite.com/html/dest

as the user "hank" password "mypassword"

Can this be done?  If so, how?

Thanks!
0
Comment
Question by:hankknight
  • 2
4 Comments
 
LVL 18

Expert Comment

by:liddler
ID: 12026132
Either use sudo, to give user webuser hank's priviledges or use eXpect (http://expect.nist.gov/) to write a script that passes the password.

sudo is probably better, with the NOPASSWD option, man sudo for details
0
 
LVL 5

Expert Comment

by:paranoidcookie
ID: 12026191
To log on to a server as a different user

ssh -l username server

or

ssh username@server

Im not 100% on what you are trying to achieve are you coping files from one server to another? Or locally copying files once logged in on the remote computer?
If its a local copy the syntax is correct if you are copying from a remote comp to local you need to use

scp -rp user@remote:/path/to/files user@local:/path/to/files

0
 
LVL 16

Author Comment

by:hankknight
ID: 12026722
Thanks!

What I am actually trying to accomplish is to get a web script to copy local files to a different local directory.  Because of this there must not be a password prompt.

Looks like sudo should do what I need.

    http://www.courtesan.com/sudo/man/sudo.html


but I can't figure out how to enter the password for "hank"

          sudo -u webadmin -p %U mypassword cp -pr /home/web/mysite.com/html/source /home/web/mysite.com/html/dest

does not work.

How can I proporly pass the username and password values?

Thanks
0
 
LVL 18

Accepted Solution

by:
liddler earned 500 total points
ID: 12026897
In your sudoers file, use
webadmin ALL=NOPASSWD: cp -pr /home/web/mysite.com/html/source /home/web/mysite.com/html/dest

Then password is not required
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now