0

I need to run a script on a machine which is only reachable trough some hopping. So I wrote a little script:

ssh -t user1@host1 ssh -t user2@host2 ssh -t user3@host3 sript_to_run.sh

This works great and prompts passwords for host1, host2 but not host3.

For convenience I copied my public rsa-key from my computer to host1 for password-less login. Now only prompting me for login in host2 but otherwise fine.

So I did the same with host1 & host2. Now I can login upto host2 without any password prompt. But I now need to login with a password on host3... Unfortunatelly I don't know how the passwordless login works on host3 and I'm not allowed to append the authorized_keys file.

So I would assume that host3 somehow knows how I logged into host2. Can I somehow trick host3 in thinking that host2 was being logged into by password prompt? Or is there an other way to run the script passwords-less?

Here is the verbose output from the last ssh step is (Everything in # is removed for anonymity):

OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to mcc-console [#IP#] port 22.
debug1: Connection established.
debug1: identity file /reg/neh/home/#USER#/.ssh/identity type -1
debug1: identity file /reg/neh/home/#USER#/.ssh/id_rsa type -1
debug1: identity file /reg/neh/home/#USER#/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '#HOST3#' is known and matches the RSA host key.
debug1: Found key in /reg/neh/home/#USER#/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Next authentication method: publickey
debug1: Trying private key: /reg/neh/home/#USER#/.ssh/identity
debug1: read PEM private key done: type DSA
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /reg/neh/home/#USER#/.ssh/id_rsa
debug1: Trying private key: /reg/neh/home/#USER#/.ssh/id_dsa
debug1: Next authentication method: password
  • 1
    posting verbose log for the step you want to investigate will help you what is going on under the hood. – Jakuje Nov 3 '15 at 19:12
  • Try restorecon -R ~/.ssh. It appears on CentOS the wrong SELinux label is assigned upon creation of authroized_keys. Theprevious command restores it to the correct value. – MariusMatutiae Nov 3 '15 at 19:37
  • @MariusMatutiae. Where should I run this? On host2? I tried it but unfortunately it tells me Command not found. – magu_ Nov 3 '15 at 19:41
0

Few remarks, not sure if it will answer all your answers:

  1. Copying your private key to remote machines is WRONG, if they are not completely trusted (physical access, root access only by you). If you really need to use your key from remote machine, there is feature called AgentForwarding, which does the thing in better way (google to read more)

  2. Setting up jumphosts is also really well known problem. Yes, you can do it the way you do it now, but you will do mistakes I mention above. And why to do them, when there is better way, called ProxyCommand? With this, you can leave all the private key operation on your trusted machine, which is desirable (google, many times solved here on superusr or on wikibooks).

And to your questions:

Can I somehow trick host3 in thinking that host2 was being logged into by password prompt?

Not sure what you mean by this.

Or is there an other way to run the script passwords-less?

There are many ways to authenticate to the server except the passwords. There is kerberos using GSSAPI, there is host-based authentication, but all of them need some setup to be done before. If you don't have any control of the host3 and you are prohibited to set up public key, you really need to use password. But without further information I can't help. The failures from server log can be also helpful to investigate the problem.

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.