0

I have two remote machines, I'm running a script on one of them.
There's some part of the script that should be running on the other one, then the script will continue in its further tasks/commands.
For some reasons I cannot establish a ssh-without-password connection, additionally, I'd not want any password prompts.

N.B: I have shared mount between them.

  • try establishing ssh-without-password using thegeekstuff.com/2008/11/… – Tejas Jul 23 '14 at 11:25
  • The thing is, there's one more user that I'll have to be logged in to - which too requires a few digits RSA Passcode - which I want to avoid. – Keyshov Borate Jul 23 '14 at 11:31
  • Why can't you establish an SSH connection with keys? It's the easiest way, and there are very few scenarios in which it wouldn't be possible. If there are additional constraints that prevent this, you need to tell us. The fact that multiple users are involved doesn't make using keys more difficult. – Gilles 'SO- stop being evil' Jul 23 '14 at 22:53
  • @Gilles You're right, but its a script so even if I use Keys/passcode I wonder how the script'd be able to Continue its further execution(like how do you let the script know that the login was successful, continue further), is it possible? – Keyshov Borate Jul 24 '14 at 6:45
  • 1
    It's easier with keys than with a password: the script just does ssh remotehost somecommand, whereas a password requires an additional layer because SSH has no way to provide a password except interactively. I don't understand why you think that keys would introduce a difficulty. – Gilles 'SO- stop being evil' Jul 24 '14 at 7:24
1

to avoid SSH password promts:

sudo apt-get install sshpass

An alternative tool for package installation is dpkg

download the sshpass deb packet

and install it:

sudo dpkg -i sshpass_1.04-1_amd64.deb

pattern to use as follows:

sshpass -p mypassword ssh user@server

if needed to avoid sudo password promt:

ssh uder@server-abc.com "echo sudo_password | sudo -S ./script.sh"

The explanation for the last one is: having sudo run after ssh, it never gets a password input for sudo on the remote server, so the solution is use -S and pipe a password for sudo as above.

  • Any alternative for apt-get?, It wouldn't work on my GNU/Linux. – Keyshov Borate Jul 24 '14 at 6:40
  • @Keys I added a bit to the answer. – Ruslan Gerasimov Jul 24 '14 at 6:50
1

For a passwordless login you should create an SSH Keygen.

For more information on the subject and how to do it see :

https://help.github.com/articles/generating-ssh-keys.

  • I've tried ssh Keygen & ssh-copy-id to my destination server, it didn't work :( – Keyshov Borate Jul 23 '14 at 12:05
  • @Keys have you used ssh-keygen for the same user your script will use? – fduff Jul 23 '14 at 12:08
  • Have tried for another user - the first level, if that succeeds then would need to find a way for another user(the second level) which then'd follow the same thing(password-less login), if at all possible(!), any workarounds? – Keyshov Borate Jul 23 '14 at 12:14
1

a.First log in on A as user a and generate a pair of authentication keys

b.Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine)

ssh b@B mkdir -p .ssh

b@B's password

c. Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:

cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'

b@B's password: d. ssh b@B Now you don't need to enter the password of B server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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