General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
02-03-2012, 02:12 PM
#1
Senior Member
Registered: Feb 2003
Location: Washington D.C
Posts: 1,966
Rep:
Using Commands over SSH using Sudo
Is there a way to transfer my sudo password via ssh so that I can copy files remotely and pass them locally, so:
Code:
cat sudo-passwd-file|ssh -t user@10.7.0.180 'sudo find / -depth|cpio -oacv|gzip' > /path/to/dir/file.cpio.gz
I am in the process of a creating a script. Everytime I try and just do this I get:
Code:
cat passwd-file|ssh -t saint@10.7.0.180 'sudo find / -depth'
Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: no tty present and no askpass program specified
??
02-03-2012, 02:52 PM
#2
Senior Member
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, Ubuntu, SLES, CentOS
Posts: 1,674
@ Reply
Hi metallica1973,
Isn't the easy way would be setting up key based authentication for that particular user and let it run commands on the remote server? You can refer following link that will help you out:
http://linuxproblem.org/art_9.html
The reason I am suggesting this because it is more secure than keeping your password in a file (plain-text)
02-03-2012, 03:15 PM
#3
Senior Member
Registered: Feb 2003
Location: Washington D.C
Posts: 1,966
Original Poster
Rep:
I appoligize for not clarifying my setup. I do use "hostbasedauthentication" and currently use passwordless ssh commands to do other stuff like:
example:
Code:
ssh -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l user 10.7.0.180 "find / -depth|cpio -oacv|gzip" > /path/to/dir/file.cpio.gz
I dont have any permission issues in this instance but now I have been ask to do the samething on another server that requires me to use my sudo password or else I will get permission issues when trying to read different files.
02-03-2012, 03:34 PM
#4
Senior Member
Registered: Feb 2003
Location: Washington D.C
Posts: 1,966
Original Poster
Rep:
Couldnt I just:
connect to 10.7.0.180 and add a newline or edit existing to look like
Code:
user ALL=(ALL) NOPASSWD: /usr/bin/find
02-03-2012, 03:51 PM
#5
Senior Member
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, Ubuntu, SLES, CentOS
Posts: 1,674
@ Reply
Yes, you can do that. However, it should look like as follows instead:
Code:
user ALL=NOPASSWD: /usr/bin/find
So that this user is only allowed to run find command with elevated privileges.
Below syntax doesn't look correct to me.
Code:
user ALL=(ALL) NOPASSWD: /usr/bin/find
02-07-2012, 12:23 PM
#6
Senior Member
Registered: Feb 2003
Location: Washington D.C
Posts: 1,966
Original Poster
Rep:
Many thanks for the reply. I made the correction made it specific to a user:
Code:
user ALL=NOPASSWD: /usr/bin/find, /bin/cpio, /bin/gzip
and noticed that now when I perform a:
Code:
ssh -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l user 10.7.0.180 "find / -depth|cpio -oacv|gzip" > /path/to/dir/file.cpio.gz
I am getting from cpio:
Code:
cpio: /etc/ConsoleKit/seats.d/00-primary.seat: Cannot utime: Operation not permitted
/etc/ConsoleKit/seats.d/00-primary.seat
/etc/ConsoleKit/seats.d
/etc/ConsoleKit
cpio: /etc/blkid.conf: Cannot utime: Operation not permitted
/etc/blkid.conf
cpio: /etc/cron.d/anacron: Cannot utime: Operation not permitted
/etc/cron.d/anacron
cpio: /etc/cron.d/.placeholder: Cannot utime: Operation not permitted
/etc/cron.d/.placeholder
/etc/cron.d
cpio: /etc/idmapd.conf: Cannot utime: Operation not permitted
This doesnt happen on my other server. Any ideas ??
Last edited by metallica1973; 02-07-2012 at 12:28 PM .
02-07-2012, 01:42 PM
#7
Senior Member
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, Ubuntu, SLES, CentOS
Posts: 1,674
@ Reply
Are you trying to say when you ssh using the user account user to other servers it works fine with sudo. However, it does not work on this particular server? If yes, then check the permission that this account has got on this server. Appears to be a file system permission issue to me.
02-07-2012, 03:48 PM
#8
Senior Member
Registered: Feb 2003
Location: Washington D.C
Posts: 1,966
Original Poster
Rep:
It does appear to be an permission issue.
Regards
02-17-2012, 09:43 AM
#9
Senior Member
Registered: Feb 2003
Location: Washington D.C
Posts: 1,966
Original Poster
Rep:
I had a senior moment and I realized that I wasnt using sudo in my statement so when testing I ran into some issues. Here is my testing scenario.
/etc/sudoers
Code:
user ALL=NOPASSWD: /usr/bin/find, /bin/cpio, /bin/gzip
I know hostbased authentication is working:
Code:
ssh -t -t -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l user 10.7.0.180
Linux 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:21 UTC 2011 i686 GNU/Linux
Ubuntu 10.04.2 LTS
Welcome to Ubuntu!
* Documentation: https://help.ubuntu.com/
Last login: Fri Feb 17 10:30:18 2012 from 10.7.0.112
user@mymachine:~$
When testing the command with sudo, it is still prompting me for a password.
Code:
ssh -t -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l user 10.7.0.180 "sudo find / -depth"
[sudo] password for user:
??
Last edited by metallica1973; 02-17-2012 at 10:36 AM .
02-17-2012, 10:35 AM
#10
Senior Member
Registered: Feb 2003
Location: Washington D.C
Posts: 1,966
Original Poster
Rep:
I even changed
/etc/sudoers
Code:
user ALL = NOPASSWD: ALL
and it still prompts for a password:
Code:
user@mymachine:~$ ssh -t -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l user 10.7.0.180 "sudo find / -depth"
[sudo] password for user:
but when just using:
Code:
ssh -t -t -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l user 10.7.0.180
Linux 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:21 UTC 2011 i686 GNU/Linux
Ubuntu 10.04.2 LTS
Welcome to Ubuntu!
* Documentation: https://help.ubuntu.com/
Last login: Fri Feb 17 10:30:18 2012 from 10.7.0.112
user@mymachine:~$
its fine. ?????????????
02-21-2012, 10:36 AM
#11
Senior Member
Registered: Feb 2003
Location: Washington D.C
Posts: 1,966
Original Poster
Rep:
It definately has to due with what I have inside of the sudoers file:
Code:
ssh -t -t -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l user 10.7.0.180
Linux 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:21 UTC 2011 i686 GNU/Linux
Ubuntu 10.04.2 LTS
Welcome to Ubuntu!
* Documentation: https://help.ubuntu.com/
user@10.7.0.180:~$ sudo find / -depth
[sudo] password for user:
As you can see, after logging in, I am still getting prompted for a password.
02-21-2012, 12:05 PM
#12
Senior Member
Registered: Feb 2003
Location: Washington D.C
Posts: 1,966
Original Poster
Rep:
It was in fact /etc/sudoers and the placement of my entry, so from:
Code:
root ALL=(ALL) ALL
user ALL = NOPASSWD: /usr/bin/find, /bin/cpio, /bin/gzip
to
Code:
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
user ALL = NOPASSWD: /usr/bin/find, /bin/cpio, /bin/gzip, /bin/cat
worked like a charm.
http://askubuntu.com/questions/10005...on-not-working
solved!!!!
Last edited by metallica1973; 02-21-2012 at 12:07 PM .
Thread Tools
Search this Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -5. The time now is 05:51 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News