Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-11-2011, 08:34 PM   #1
LQ Newbie
Registered: Jul 2011
Posts: 4

Rep: Reputation: Disabled
ssh "user@host cmd" from root

I’ve used your method to ssh without a password for a non-root user, say “user”. This works as long as I’m logged in as “user”.
But if I run as root, the following still asks for “user”‘s password.
i.e.: the following works w/o a password:
su – user
ssh host date
But the following asks to the password of “user”:
su – root
ssh user@host date
Old 07-11-2011, 09:52 PM   #2
Senior Member
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 651Reputation: 651Reputation: 651Reputation: 651Reputation: 651Reputation: 651
I'd have to guess that you've set up ssh key based authentication for root@host not user@host ... as these are 2 different users on the remote system you'll need to set it up for both.
Old 07-12-2011, 12:42 AM   #3
LQ Newbie
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
I copied the .ssh/authorized_key2 file under the "user" account onto the remote host. That's why if I become "user" on local host, I can ssh to user@remotehost without a password. What I'm actuaaly trying to do is to write to tape on the remote host; the local host is Solaris 10 while the remote host is RHEL 5.6; e. g.:
cd /; /bin/tar Ecfb - 200 opt | ssh user@remotehost 'dd of=/dev/nst0 bs=200b'
Old 07-12-2011, 12:56 AM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,511

Rep: Reputation: 2415Reputation: 2415Reputation: 2415Reputation: 2415Reputation: 2415Reputation: 2415Reputation: 2415Reputation: 2415Reputation: 2415Reputation: 2415Reputation: 2415
ssh works on a pair of keys.
The user's (local) key is only visible from the user's acct, not the root acct.
I think you want (if starting from root)
su - user -c "ssh user@remotehost ..."
theoretically you can skip 'user' part of ssh cmd, as it'll default to current user, if that's what you want.
Old 07-12-2011, 11:04 AM   #5
LQ Newbie
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
That worked!

That worked, thank you very much:
e.g.: su - user -c "ssh remotehost uname -a"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Command logging ideas needed! ssh user@host "echo logme" ZiGz Linux - Security 6 04-15-2009 02:08 AM
How to disable remore ssh login access of "root" user. ashishshukla Linux - General 3 10-07-2008 08:55 AM
SSH Keybased authentication for "root" user on linux. adastane Linux - Networking 2 12-13-2007 03:57 AM
"Can't resolve host" as user, but works fine as root truthe Linux - Networking 2 10-22-2006 05:41 PM
"su root" fails when I connect with normal user thru SSH AlinFaur Linux - Security 5 02-22-2006 11:26 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:32 PM.

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