Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to deploy an executable and execute it on remote Unix machine(Linux/Solaris) from Linux without entering the password manually.

I tried scp and also SSH key-gen utility to interact with remote server but in either way i couldn't avoid providing the password manually. Since I need to run this command/utility from Java code, I should completely avoid prompting for the password at run time. I have gone through many topics in google but nothing has been materialized.

How can I do this?

share|improve this question
add comment

3 Answers

You should set up authentication using public/private keypair as you already mentioned you generated using ssh-keygen. Have it generated without a password on the private key if you need to use it in automated scripts. Now, just copy over the public key using ssh-copy-id name@host to set it up correctly on the remote side (authorize public key).

I suggest you to follow a tutorial like this one.

If ssh works, then scp works likewise.

After setting it up correctly, you should be able to do this without interaction:

scp myscript.sh name@remotehost:~/
ssh name@remotehost ~/myscript.sh

To avoid having to enter a password or passphrase there are a couple of choices

  • use an authentication agent to hold the password/passphrase for the private key
  • don't use any pass-phrase to protect the private key

The first is appropriate for interactive use, the latter is less secure. You should probably set up a new user-id for this with minimal rights at the far end (e.g. chrooted)

share|improve this answer
    
You beat me to it. I'll merge my (now deleted) answer into yours, please undo if you object. –  RedGrittyBrick Dec 6 '12 at 11:06
add comment

You need to read about rhosts and rlogin.

http://vegdave.wordpress.com/2007/05/17/how-to-rloginrcprsh-to-a-machine-without-enter-a-password/

share|improve this answer
    
Is this secure? It seems a sort of unencrypted remote shell. –  gertvdijk Dec 6 '12 at 11:00
add comment

Step 0. You must have ssh access to remote machine.

Step 1. Generate RSA private/public key pair with ssh-keygen on your Linux box and place it somewhere (/root/identities, for example). Provide no passphrase.

Step 2. ssh-copy-id -i /root/identities/your.key user@remotemachine.tld

Step 3. This is it. Now you may ssh -i /root/identities/your.key user@remotemachine your_command and no password would be prompted. Sure, you must have PubkeyAuthentication = yes in remote machine's sshd_config.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.