0

Possible Duplicate:
pass password to su/sudo/ssh
SSH in shell scipt with password

Is there any possibility I can pass password for ssh command

ssh root@10.20.30.40 | echo "Password" (or)      
echo "Password" | ssh root@10.20.30.40 (or) a script like below  
pw1="Password"
ssh -t root@168.56.64.245 <<< EOF  
$pw1  
EOF

Any solution can be helpful.

I was on windows and I was connecting to Linux host with putty and from that Linux to another Linux host. The problem is I can't use any 3rd party tools on Linux hosts and I can't add rsa-keys also.

Community
  • 1
  • 1
Sunny
  • 175
  • 4
  • 11

3 Answers3

0

I know you can not add , but look if sshpass is installed

Stéphane
  • 797
  • 3
  • 6
0

Use expect. See here

I used it in one my projects. It was really helpful. It is a bit long to implement but the logic is easy - after the ssh "query" you just "expect" for something you wrote after the command expect as a regexp. Hope it helps.

0xmtn
  • 2,476
  • 5
  • 24
  • 50
0

Use expect, here a script example:

#!/usr/bin/expect -f
    set timeout 20
    set IPaddress [lindex $argv 0]
    set Username "your_username"
    set Password "your_password"
    set Directory DIRECTORY_PATH

    log_file -a $Directory/session_$IPaddress.log
    send_log "### /START-TELNET-SESSION/ IP: $IPaddress @ [exec date] ###\r"

    spawn telnet $IPaddress
    expect "Username: "
    send "$Username\r"
    expect "Password: "
    send "$Password\r"
    interact
    send_log "\r### /END-TELNET-SESSION/ IP: $IPaddress @ [exec date] ###\r"
exit

Source : Expect scripts for automatic login with telnet and SSH

EDIT: If you dont want to use expect tool you should try to log using ssh key exchange

EDIT2 : I read you dont wanna use except or key exchange but I'm not sure this could be accomplished without these.

Check this post:

SSH Automatic Login

Another option:

http://sourceforge.net/projects/sshpass/

Carlos Landeras
  • 10,594
  • 11
  • 51
  • 81
  • Thanks for you response but its restricted to use tools like Expect – Sunny Nov 30 '12 at 22:51
  • Updated my answer. If you dont want to use expect tool you should try to log using ssh key exchange – Carlos Landeras Nov 30 '12 at 22:54
  • Carlos Lande, please do refer the question. I can't use any 3rd party tools or ssh-keys. But Thank you. – Sunny Nov 30 '12 at 22:56
  • I read it, but I think it is not possible. Password are meant to be introduced by human, the terminal is specting it so if you dont use certificate trust of external tools I think it can't be accomplished. I will check this question close, if there is a method I also would like to know it. Thanks ;) – Carlos Landeras Nov 30 '12 at 22:58
  • Thanks Carlos. I appreciate your help. – Sunny Nov 30 '12 at 23:02