Solved

changing user for command

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.
Suggested Courses

622 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