Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: perl & ssh
by azatoth (Curate) on Aug 16, 2001 at 16:26 UTC | |
Yep. When you set up your ssh stuff using ssh-keygen, you set a password which is stored in authorized_keys. Simply re-run /usr/bin/ssh-keygen, and hit enter twice when prompted for the password. job done. Azatoth a.k.a Captain Whiplash Make Your Die Messages Full of Wisdom!Get YOUR PerlMonks Stagename here! Want to speak like a Londoner? | [reply] |
by Anonymous Monk on Aug 16, 2001 at 18:00 UTC | |
| [reply] |
by azatoth (Curate) on Aug 16, 2001 at 18:06 UTC | |
IMHO, switching to root is *always* fairly dangerous. Usually because I have fat fingers and end up ruining something or other. I have no definitive answer to your 2nd question, but advise you to have a look at a thread I started a while ago, which i think might help. It's about SSH and Different Users. HTH Azatoth a.k.a Captain Whiplash Make Your Die Messages Full of Wisdom!Get YOUR PerlMonks Stagename here! Want to speak like a Londoner? | [reply] |
by echo (Pilgrim) on Aug 16, 2001 at 20:13 UTC | |
You lose the interactivity ("your command failed: $errormsg") but that can only be reached I think by giving root privs to your web server, something you really really don't want to do. | [reply] |
Re: perl & ssh
by Anonymous Monk on Aug 16, 2001 at 21:26 UTC | |
As it appears to me the intent of the original author is to: 1. Create a web-based administration interface 2. Use this interface to cause the execution of root privileged commands on a machine other than the webserver 3. Do so in a manner that is "secure" To accomplish this, the author is asking how to perform items 2 and 3 without the need to specify a password or any other type of manual intervention in the authentication process. To the original author, what you are doing is reasonable, but you need to consider several things to ensure that your system can't be easily abuse to exploited: - How to prevent an authorized user from escalating their privileges. I've seen several CGI applications that use hidden fields to key actions. These hidden fields are then passed to an action script which blindly trusts its passed parameters. There is nothing to stop an attacker from modifying the form and posting it to the action script to do bad things. A simple fix is to include some kind of secret-derived value, such as an HMAC of the form variables plus a secret key, when you post to the action script. Have the action script check this result to make sure bad things aren't taking place. Check out Digest::HMAC. - Intermediate files create race conditions! This may not be an issue for your particular case but be wary. Particularly since you would have a root privileged process making decisions based on the contents of the file. Now to deal with your need for remote execution. There are a couple of ways you can do this: 1. Have your script issue the remote commands directly to the remote host. This seems to be the path your are already on using SSH. 2. Run a process on the remote machine that listens on a port and processes requests as they come in. 3. Use something like Rexec or Rsh Don't do option 3; it's security nightmare. Option 1 is fine and it seems that what you're already trying to do via SSH. If you can get the password issues worked out that's fine however you are giving a script full-blown account access. From your follow-ups it looks as if you are doing this via an RSA key without a password. That's a _lot_ of trust for the machines and processes. Security principals dictate that we minimize privileges and trust. If you choose to do it this way, limit the account's privileges with sudo or something similar. Also strongly consider using tcp_wrappers to provide additional fine-grained access control to the SSH processes. I would suggest you also consider option 2. The password/account issues goes away. Instead, you will need to create a small daemon on the remote end that listens for requests from the web script. This daemon has a list of actions it will perform and no more. To protect this channel you can utilize a blizzard of options. Since confidentiality for this connection is not a concern utilize a scheme similar to the one I described above: a shared secret between the daemon and the CGI process that is used to key an HMAC of the request. I just previewed my response and realized how long it's become so I'll stop now. The whole reason I can write this much is because I have both screwed-up and taken advantage of many screw-ups related to remote command execution. Just understand that because it's on an "internal" network doesn't mean you can trust that network or drop your guard. | [reply] |
Re: perl & ssh
by Tuna (Friar) on Aug 16, 2001 at 20:31 UTC | |
Copy the contents of the user's identity.pub on the local machine, and append it to that user's authorized_keys file on the remote machine. Then, I run an instance of sshd, as that user, and define an obscure port to connect to. You will need to create an sshd_config_<user>, and tell sshd to use that file. | [reply] |
Re: perl & ssh
by trantor (Chaplain) on Aug 16, 2001 at 17:31 UTC | |
I can't see why you need ssh if you don't want to have passwords... To me this looks like giving to a third party the possibility to login remotely to another server doing whatever they want. And the nice bit is that the third party can't even be eavesdropped :-) I'm not criticizing your choice, you might have good reasons to do it (very good reasons, I hope), but at this point you can simplify your life and use Net::Rexec or similar, keeping your keys safe with a password (because you might use them for other connections as well). Happy remote execution! (No pun intended) -- TMTOWTDI | [reply] |
by c (Hermit) on Aug 16, 2001 at 18:22 UTC | |
As far as Rexec goes, I dont believe that Rexec is encrypted traffic, which, if we're nitpicking, would cause most infosec people to gasp out loud. Sure it can be encrypted just like rsync using ssh as the transport. So why not just use ssh to begin with? To the original poster, if you need the user logging in to the remote box to issue superuser level commands, you might want to look into using sudo. Here is a pretty good and complete guide on using it. Once you get into this arena, you will also need to be careful about what sudo permission you allow the account that ssh's into the machine, so you're back to square one when it comes to planning your security measures, but so goes the business. I read that Security and Convenience are inversely proportional. You'll have to be the one to decide where you draw the line at convenience and sleeping well at night. humbly -c | [reply] |
by vaevictus (Pilgrim) on Aug 16, 2001 at 19:13 UTC | |
| [reply] |
by mr_mischief (Monsignor) on Aug 16, 2001 at 18:33 UTC | |
To me this looks like giving to a third party the possibility to login remotely to another server doing whatever they want. And the nice bit is that the third party can't even be eavesdropped :-) This is true only so long as the third party already has access to your account on the local machine. If they do, chances are a keylogger wouldn't be too hard a thing to use in case you weren't using public key encryption to authenticate to another box. That way, they still have access, and you are none the wiser. Besides, ssh logs pretty thoroughly. If you don't trust public key encryption, remember never to trust SSL or TLS on a web site. Secure shell is no different. Chris | [reply] |
by Anonymous Monk on Aug 16, 2001 at 18:20 UTC | |
| [reply] |
Re: perl & ssh
by scottstef (Curate) on Aug 16, 2001 at 17:21 UTC | |
Edit:I did not completely comprehend what the question was asking. Please ignore my remark. I will never again attempt to respond to without a morning cup of coffee. "The social dynamics of the net are a direct consequence of the fact that nobody has yet developed a Remote Strangulation Protocol." -- Larry Wall | [reply] |
by vaevictus (Pilgrim) on Aug 16, 2001 at 17:51 UTC | |
Obviously, all this person wants to do is connect to one of his own boxes with ssh (which requires some form of authentication). To do this autonomously requires that you not have to do local authentication to your public key.
SSH can do public key authentication, which is both more secure than password authentication, and also provides for an additional layer of authentication at the local level. To connect to a box with ssh && public key authentication, usually you password your public key so that only you can use that file to connect. | [reply] |