LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-08-2011, 09:56 AM   #1
Noobux
LQ Newbie
 
Registered: Nov 2010
Location: Florida
Distribution: Ubuntu 17, RHEL 5,7
Posts: 11

Rep: Reputation: 1
Question SSH for remote execution?


We are on our first Linux platform and I am trying to coordinate a distributed application backup across multiple machines. I am trying to write a script in which I would have used RSH to execute scripts on the other servers. We are no longer allowed to use rsh, and someone suggested ssh. I am using that instead of telnet, but I am not sure of the syntax.

"rsh server [-n] path/executable" is what I would have used, just not sure of the syntax for ssh.

Yes I am looking at the man pages, but I can't get it to execute without prompting for a password.

Any help is appreciated.
 
Old 02-08-2011, 10:03 AM   #2
unixfool
Member
 
Registered: May 2005
Location: Northern VA
Distribution: Slackware, Ubuntu, FreeBSD, OpenBSD, OS X
Posts: 782
Blog Entries: 8

Rep: Reputation: 158Reputation: 158
If you had key-based authentication enabled, you might be able to do this, with or without a key passphrase. Obviously it will work without a passphrase, but many people go this route because of the difficulty of doing it with passphrase. It can be done (using ssh-agent, which has a manpage, BTW).

I hope this info is enough to see you through to your intended results.
 
Old 02-09-2011, 03:35 AM   #3
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Depending whether the admins like it: it's possible to run a second sshd on the target machine on a different port allowing login only from certain machines. Normally I advice the users to use an ssh-agent as mentioned as it's really convenient, but for some automatic processing I don't like having the agent running all the time and check this - the backup process might fail because the agent crashed for any reason. So this can be an exception to have a dedicated passphraseless ssh-key for a special "backup user" which is only for one purpose: accessing exactly this machine on a special port.

Another option could be hostbased authentication, then you don't need any ssh-keys or filled personal ~/.ssh/known_hosts file.

Last edited by Reuti; 02-09-2011 at 03:36 AM. Reason: Typo
 
Old 02-09-2011, 07:22 AM   #4
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
Good that you can't use rsh anymore. Gaping security hole. Telnet as well.

SSH is routine and easy in these situations, but be sure not to do it with root. For example, I have backup routines that have to run as root. In those situations where a remote tape drive is needed, the backup script does an su to a backup user piping the backup stream through that user and ssh to the tape drive on the remote system. So, how...

The user that the script is going to use for ssh needs to be configured for public key authentication. My favorite howto has disappeared from the web, BUT, the wayback machine comes to the rescue. You can get an explanation and details on how to do the ssh public key setup here http://web.archive.org/web/200712191...ublickey-auth/.

Following are a couple of example's of the ssh syntax embedded in an su in my backup script. They seem a bit complex, but it's easy to decompose them. In the first one all the pieces of the ufsdump command and the capture of its status code are enclosed in parenthesis to make it a subprocess (otherwise I couldn't both catch the status code and pipe the output). The output from that subprocess is then piped to the su. The su uses the -c followed by a quoted string to specify the command to be executed. That command is the ssh. The ssh then takes a quoted string at the end to indicate the command to be executed on the remote system. The quotes for that string have to be escaped since they are inside another quoted string. It looks a bit more complicated because of all the script variables used in the parameters.

I've also used ssh key access limits to restrict the use of the key so that only the machines doing backups are allowed access and only to do the specific commands needed. That is also explained in the guide I linked to above. Details can also be found in `man authorized_keys`.

Code:
( /usr/lib/fs/ufs/ufsdump ${LEVEL}cnlTfuN 2h - ${RDEV} ${WHICHSNAP}; \
  STATCODE=$?; \
  echo ${STATCODE} > ${CODEFILE} ) \
   | su - backup -c "ssh ${TAPESERVER} \"dd obs=64b of=${TAPDEV}\"";
Code:
su - backup -c "ssh ${TAPESERVER} \"mt -f ${TAPDEV} rewoffl\"" ;
 
Old 02-09-2011, 08:31 AM   #5
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Add-on to choogendyk's implementation:

What about using sudo instead of su? Inside /etc/sudoers it can also be specified, that a:
Code:
sudo ssh ${TAPESERVER} dd obs=64b of=${TAPDEV}
will switch automatically to the backup user, when the string matches:

Code:
Cmnd_Alias BACKUP = /usr/bin/ssh [a-zA-Z]* dd obs=64b of=[a-zA-Z]*
Defaults!BACKUP runas_default=backup, always_set_home
the_user   ALL = (backup) NOPASSWD: BACKUP
(replace the_user with the user who is granted access to it [it can also be a group]).

It won't need a password due to the NOPASSWD: option, but it can only be used for exactly this command and nothing else.
 
Old 02-10-2011, 06:03 AM   #6
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
sudo is for providing tightly controlled privileges to a user who wouldn't otherwise have them. In this case it is an unnecessary added complication. My backup script is running as root. The issue is that root shouldn't be allowed to login to another computer. So, you su to an unprivileged user that will log in to the other computer. Root can su without a password. The unprivileged user then logs in to the other computer using ssh with public key authentication. That key is restricted on the other computer to only allow this computer for this usage.

If you don't need root (I used root because it was a backup script running fssnap and ufsdump) then you don't need the su. The unprivileged user, typically a special user for a particular application, runs the script and makes the connection to the other computer using public key authentication.
 
Old 02-10-2011, 06:07 AM   #7
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Aha - I wasn't aware that you run it from root itself, hence I thought switching to the backup user would need a password.
 
Old 02-10-2011, 06:44 AM   #8
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Rep: Reputation: 32
1. To execute some script in remote machine,u must have to give the passwd of remote machine.
In other word, you must own the right permission.

2. Else change the effective id of the executable before u access that.
 
Old 02-18-2011, 10:29 AM   #9
Noobux
LQ Newbie
 
Registered: Nov 2010
Location: Florida
Distribution: Ubuntu 17, RHEL 5,7
Posts: 11

Original Poster
Rep: Reputation: 1
Smile Thanks

Thanks to all for your replies. I am having the server team setup the appropriate ID permissions across the servers so SSH won't prompt for pwds.

Appreciate all your time and thoughts,
Kevin
 
  


Reply


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
Escape command for remote ssh execution brianmcgee Linux - Software 2 06-14-2010 06:34 AM
Remote execution over SSH - incomplete environment echa Linux - Server 5 10-06-2009 10:14 AM
Automated execution of a command on a remote system via SSH GUIPenguin Linux - General 1 02-28-2006 11:23 PM
ssh : remote command execution doesn't work for modifying env variables pypieuvre Programming 10 02-24-2006 09:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:21 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