Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

changing user for command


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!
Avatar of liddler
liddler
Flag of Ireland image

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
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

Avatar of hankknight

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of liddler
liddler
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial