Solved

changing user for command

Posted on 2004-09-10
4
246 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

920 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

13 Experts available now in Live!

Get 1:1 Help Now