1

I have a program that requires cascaded SSH, i.e. it ssh A server and then using same connection ssh B server. Server A is acting as a bridge. I have an instance of shell which is used to ssh first server.

When I am doing ssh user@ipAddress, it asks for password. I tried ssh user@ipAddress\npassword. It doesn't seem to be working.

I cannot use any external tools like ssh-agent or expect. I have no control over the server A.

Is there a way I can provide password as an argument or enter password?

Thanks!!

Mo3z
  • 2,138
  • 7
  • 21
  • 29

3 Answers3

3

You should generate a RSA key on the client

ssh-keygen

and put the public key in the authorized key in the authorized_key folder on the server to be able to connect to the server without a password.

An step by step guide is given here.

Edit: If you have no access to the server, use a ssh-library for Java as decrived in this question.

Community
  • 1
  • 1
lc2817
  • 3,722
  • 16
  • 40
  • I have no control over server A. I cannot install any certificate. The only thing I can do is, use ssh. – Mo3z Nov 17 '11 at 21:18
  • I updated my answer check the code snippets in this thread you will find your answer – lc2817 Nov 17 '11 at 21:20
  • Thanks lc2817. My problem is not connection to server A. I am able to SSH server A. Your answer provides me the solution to that. I need SSH from server A to server B using the same connection. Thank you! – Mo3z Nov 17 '11 at 23:56
1

Either you can setup the password-less login or you can just feed the password like described here:

ssh -t -t <machine> <<EO_MY_INPUT
<password>
date # (or whichever is the command to get date/time)
exit
EO_MY_INPUT
Kashyap
  • 15,354
  • 13
  • 64
  • 103
0

Since you cannot use expect or ssh-keygen

The following gem can be used to script a password ssh session

http://www.debian-administration.org/articles/587

#!/bin/bash
# Copyright (C) 2008 John S. Skogtvedt <jss at bzz.no>
# Licence: GNU GPL v3 or later at your option

if [ -n "$SSH_ASKPASS_FD" ]
then
        read password <&$SSH_ASKPASS_FD
        echo "$password"
        exit 0
elif [ $# -lt 1 ]
then
        echo "Usage: echo password | $0 <ssh command line>" >&2
        exit 1
fi

export SSH_ASKPASS=$0
export SSH_ASKPASS_FD=4
[ "$DISPLAY" ] || export DISPLAY=dummy:0
read password

exec 3<&0
# write password 100 times to make repeated ssh connections work
for x in $(seq 100)
do
  echo "$password"
done | exec setsid "$@" 4<&0 0<&3

Save the above as asksshpass.sh can chmod +x

echo "yourpassword" | ./sshaskpass.sh ssh user@server.example.com date
Gareth Davis
  • 27,701
  • 12
  • 73
  • 106