LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-08-2011, 01:09 PM   #1
zakzy
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Rep: Reputation: Disabled
Running a command on a remote server asks for password (debian)


hello,

I am not seeing what i am doing wrong here, but here goes:

From my server I need to run a command for backup on 25 remote servers (through a script). Now I have pushed the public keys for remote ssh connectivity on all of them and it works ( I can push files using rsync without the need to enter passwords on the remote servers), howver, I need to run the following command:

ssh odsadmin@10.139.111.1 'cp -a /var/www/life /var/www/life-v4'

when I run this command, I keep getting asked to enter the password, I even tried putting sudo in front of the cp, but still get the request to enter the password.

Am I missing something, or need additional steps here ?

Any help is very much appreciated.

Many thanks,

ZZ.
 
Old 07-08-2011, 03:44 PM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Hi there,

Welcome to LQ!!!

Why you putting a ' before and after the command. I mean we never run that way on local server and as you have configured ssh without password it should be like you run a command on a local server. Trying removing ' from the command and see if that work.

As you said ssh works and you dont have to enter the password. I hope you have configured it following way: http://www.dotkam.com/2009/03/10/run...h-no-password/
 
Old 07-08-2011, 10:07 PM   #3
pafoo
Member
 
Registered: Jul 2011
Location: Alabama
Distribution: Red Hat/Ubuntu/Solaris
Posts: 37

Rep: Reputation: 11
Quote:
Originally Posted by T3RM1NVT0R View Post
Hi there,

Welcome to LQ!!!

Why you putting a ' before and after the command. I mean we never run that way on local server and as you have configured ssh without password it should be like you run a command on a local server. Trying removing ' from the command and see if that work.

As you said ssh works and you dont have to enter the password. I hope you have configured it following way:
He is using the paren's because that tell's SSH to run a single command and disconnect. Normaly used with a ssh -q to keep all the exchanges hushed.

You need to verify that your id_rsa.pub was copied VERBATIM to the that servers users /home/odsadmin/.ssh/authorized_keys.

Then verify that the files and folders you are moving around have the permissions set for user odsadmin

Last edited by pafoo; 07-08-2011 at 10:09 PM.
 
Old 07-09-2011, 07:07 AM   #4
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

@ pafoo

Quote:
He is using the paren's because that tell's SSH to run a single command and disconnect. Normaly used with a ssh -q to keep all the exchanges hushed.

You need to verify that your id_rsa.pub was copied VERBATIM to the that servers users /home/odsadmin/.ssh/authorized_keys.

Then verify that the files and folders you are moving around have the permissions set for user odsadmin
SSH will anyway going to exit when you run the command: ssh username@server ls -l or any command. I don't see any significance of using ' in the command line but you can use it. Not sure what do you mean by exit. I am assuming you mean getting back to the original server console once command it execute. As per my testing that works with '.

Just try it.

@ zakzy

Did you try creating an script on the destination and then calling it from source server via ssh? Something like this:

1. vi /home/user/copy.sh
2. Enter the following contents in the file: cp -a /var/www/life /var/www/life-v4
3. Save and exit the file
4. chmod 777 /home/user/copy.sh (set the file permission as required, I am just giving an example)
5. From the source server call that script using the following: ssh odsadmin@10.139.111.1 /home/user/copy.sh

Let us know if it works.
 
Old 07-09-2011, 11:23 AM   #5
zakzy
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hello ...

Thank you for your welcome and your replies...

The command without ' ' works, but it still asks for the password.

I then followed the instructions of writing the copy.sh file, and then ran the command from my local server, but this time I got the following message:

ssh odsadmin@10.139.111.1 /home/odsadmin/copy.sh
cp: cannot create directory `/var/www/life-v4': Permission denied

Running the command with sudo asks for the password.


The rsa keys are copied over correctly, as when running rsync to send a file to the remote server, I do not get prompted for a password, the rsync just starts copying automatically.

Do I need to edit the the permissions for odsadmin and it is writing to a file on the remote server ?
This is what permissions the remote server directory has:

drwxr-xr-x 23 odsadmin odsadmin 4096 2011-07-09 16:09 odsadmin

Many thanks again.

ZZ.
 
Old 07-09-2011, 11:46 AM   #6
pafoo
Member
 
Registered: Jul 2011
Location: Alabama
Distribution: Red Hat/Ubuntu/Solaris
Posts: 37

Rep: Reputation: 11
Fair enough, I think I've always used the quotes just as a habbitt then!


Your permissions are still not set. Check the permissions on the file and the var directories. Generally var/www is owned by user apache I thought. To fix the passeord give your user osadm sudoers rights via visudo with the NOPASSWD option after the ALL:ALL statement if you want.

As a test please run the following command

Code:
ls -al /var/www
Post the results please
 
Old 07-09-2011, 12:27 PM   #7
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

pafoo is right. It appears that odsadmin does not have rights on /var/www . As suggested by pafoo run ls -al /var/www . I would also suggest running getacl /var/www to see if there is any acl set on the directory.
 
Old 07-09-2011, 01:37 PM   #8
zakzy
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hello ...

Thanks for your perserverence ...

The output of the command is this:


drwxr-xr-x 12 root root 4096 2010-08-16 11:01 .
drwxr-xr-x 17 root root 4096 2008-12-08 17:49 ..
drwxr-xr-x 2 root root 4096 2008-08-01 12:28 apache2-default
-rwxr--r-- 1 root root 208 2010-07-30 08:45 crossdomain.xml
-rw-r--r-- 1 root root 0 2008-10-23 09:37 favicon.ico
-rw-r--r-- 1 root root 45 2009-11-24 16:08 index.html
drwxr-xr-x 28 www-data www-data 4096 2010-08-16 11:01 life

drwxr-xr-x 12 root root 4096 2010-08-16 11:01 .
drwxr-xr-x 17 root root 4096 2008-12-08 17:49 ..
drwxr-xr-x 2 root root 4096 2008-08-01 12:28 apache2-default
-rwxr--r-- 1 root root 208 2010-07-30 08:45 crossdomain.xml
-rw-r--r-- 1 root root 0 2008-10-23 09:37 favicon.ico
-rw-r--r-- 1 root root 45 2009-11-24 16:08 index.html
drwxr-xr-x 28 www-data www-data 4096 2010-08-16 11:01 life
drwxr-xr-x 3 www-data www-data 4096 2009-12-03 09:49 life-v2
drwxr-xr-x 25 www-data www-data 4096 2010-06-17 13:57 life-v3
-rw-r--r-- 1 root root 20 2010-06-04 12:27 testPHP.php

I would like to avoid putting the NOPASSWD for odsadm if it is at all possible as what I need to do needs to be done on around 25 servers ... is there another option ?

Many thanks,

ZZ.
 
Old 07-09-2011, 03:35 PM   #9
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Code:
 cp -a /var/www/life /var/www/life-v4
You are trying to copy all the contents of /var/www/life to /var/www/life-v4 directory. I would suggest setting up acl for that particular user on that particular directory. Try the following on one of the server and if it works perform on the other servers as well. The problem here is that the user account does not have the sufficient rights on the location where you are trying to create the file. You have to perform it manually on all server. The best you can do is to ssh as normal user and then su - root. Following are the steps:

1. mkdir /var/www/life-v4
2. chown www-data:www-data /var/www/life-v4
3. setfacl -m odsadmin:rwx /var/www/life-v4 (You have to do the same for life directory if the user odsadmin does not have rights on it)
4. Try running the command using ssh odsadmin@10.139.111.1 /home/odsadmin/copy.sh or the way you were trying in the beginning: ssh odsadmin@10.139.111.1 'cp -a /var/www/life /var/www/life-v4'
 
Old 07-11-2011, 06:37 AM   #10
nooneknowme
Member
 
Registered: Feb 2008
Location: Bangalore, India
Posts: 69

Rep: Reputation: 5
To troubleshoot, I would start by asking you the following questions...

1. Can you run the cp command you are using in ssh, locally on the server using the user "odsadmin"
2. Is the UID of "odsadmin" same on all servers ? ( They will be if the user is centralized )
3. Is there a problem only with the cp command or can you run other commands (eg ssh odsadmin@10.139.111.1 uptime )
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ultimate Debian Live CD asks for Login and Password _IMS_ Debian 7 10-21-2010 07:18 PM
[SOLVED] Sudo command occasionally asks for root password ubuntuv Linux - Newbie 25 09-14-2010 01:26 PM
[SOLVED] Running a command on remote system . deelinux Linux - Newbie 5 06-29-2010 11:52 AM
How to enter a password before running script, with you irda remote controller ? frenchn00b Linux - General 1 11-17-2007 08:06 AM
remote command over ssh, password prompt linowes Linux - General 2 10-27-2002 08:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration