在不使用公钥身份验证或期望的情况下自动化 SSH(1) [英] Automate SSH without using public key authentication or expect(1)

查看:13
本文介绍了在不使用公钥身份验证或期望的情况下自动化 SSH(1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法自动将密码传递给 ssh.我想通过某种方式让 ssh 从标准输入或文件读取密码,使用公钥身份验证或期望脚本自动 ssh 到服务器.

Is there a way to pass a password to ssh automatically. I would like to automatically ssh to a server without using public key authentication or expect scripts, by somehow getting ssh to read the password from stdin or a file.

之所以必须这样,是因为我想将我的文件备份到使用 rsync/ssh 作为 cron 作业运行的服务器上.该服务器对我进行身份验证后挂载我的主目录,因此使用公钥身份验证不起作用,因为 ~/.ssh 在登录成功之前不可用.expect(1) 是不可能的,因为我想将它作为 cron 作业运行,并且由于 cron 作业不在终端下运行,expect/ssh 的组合不起作用.我没有对该服务器的 root 访问权限,并且很难让管理员对那里的工作方式进行任何更改.

The reason it has to be that way is that I would like to backup my files to a server using rsync/ssh running as a cron job. This server mounts my home directory after it authenticates me, so using public key authentication does not work since ~/.ssh isn't available until after the login is successful. expect(1) is out of the question because I would like to run it as a cron job, and since cron jobs don't run under a terminal the combination of expect/ssh just doesn't work. I do not have root access to that server, and it would be difficult to get the admins to make any changes to the way things work there.

推荐答案

使用sshpass.

例如,当密码在password.txt文件中时:

For example, when password is in password.txt file:

sshpass -fpassword.txt ssh username@hostname

(取自类似问题的答案)

这篇关于在不使用公钥身份验证或期望的情况下自动化 SSH(1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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