Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enter ssh password using bash? [duplicate]

Tags:

bash

ssh

Everyday I am connecting to a server through ssh. I go through this routine:

IC001:Desktop user$ ssh [email protected] [email protected]'s password:   Last login: Tue Jun  4 10:09:01 2013 from 0.0.0.0 $ 

I would like to automate this process and create a bash script to do it for me. I don't care about security and okay to store my password openly in the script. I am also okay for it to get typed openly on the screen while the script gets executed. So I've created this:

#!/bin/bash           ssh [email protected] echo mypassword 

But it doesn't work. I've also tried send instead of echo, but it also didn't work. Please advise if it is possible to do.

like image 203
Prostak Avatar asked Jun 04 '13 21:06

Prostak


People also ask

How do I pass a password using ssh in Linux?

For ssh you can use sshpass : sshpass -p yourpassphrase ssh user@host .

Can we pass password in ssh?

Combining the use of SSHPASS and SSH to access a remote server, router, or firewall gets rid of unnecessary two-liner commands that lead to an additional password entry prompt. It makes your remote access to other Linux environments faster and efficient.


1 Answers

Double check if you are not able to use keys.

Otherwise use expect:

#!/usr/bin/expect -f spawn ssh [email protected] expect "assword:" send "mypassword\r" interact 
like image 72
michas Avatar answered Oct 16 '22 22:10

michas