使用脚本自动输入SSH密码 [英] Automatically enter SSH password with script

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

问题描述

我需要创建一个脚本,该脚本自动向OpenSSH ssh客户端输入密码.

I need to create a script that automatically inputs a password to OpenSSH ssh client.

假设我需要使用密码a1234b SSH进入myname@somehost.

Let's say I need to SSH into myname@somehost with the password a1234b.

我已经尝试过...

#~/bin/myssh.sh
ssh myname@somehost
a1234b

...但这不起作用.

...but this does not work.

如何将此功能添加到脚本中?

How can I get this functionality into a script?

推荐答案

首先,您需要安装 sshpass .

  • Ubuntu/Debian:apt-get install sshpass
  • Fedora/CentOS:yum install sshpass
  • 拱门:pacman -S sshpass
  • Ubuntu/Debian: apt-get install sshpass
  • Fedora/CentOS: yum install sshpass
  • Arch: pacman -S sshpass

示例:

sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM

自定义端口示例:

sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM:2400

注释:

    传递-f标志时,
  • sshpass也可以从文件读取密码.
    • 如果执行ps命令,则使用-f可以防止显示密码.
    • 存储密码的文件应具有安全权限.
    • sshpass can also read a password from a file when the -f flag is passed.
      • Using -f prevents the password from being visible if the ps command is executed.
      • The file that the password is stored in should have secure permissions.

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

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