Solved

changing user for command

Posted on 2004-09-10
4
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
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…
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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