如何使用bash输入SSH密码? [英] How to enter ssh password using bash?

查看:1282
本文介绍了如何使用bash输入SSH密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每天我通过ssh连接到服务器。我通过这个程序:

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

IC001:Desktop user$ ssh user@my.server.com
user@my.server.com's password: 

Last login: Tue Jun  4 10:09:01 2013 from 0.0.0.0
$

我想这个过程自动化,并创建一个bash脚本来为我做。我不关心安全性和好公开储存我的密码在脚本中。我也没关系它得到公开在屏幕上,而脚本被执行类型。所以我创造了这个:

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 user@my.server.com
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.

推荐答案

仔细检查,如果你不能够使用的密钥。

Double check if you are not able to use keys.

否则,使用期望:

#!/usr/bin/expect -f
spawn ssh user@my.server.com
expect "assword:"
send "mypassword\r"
interact

这篇关于如何使用bash输入SSH密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆