SFTP 自动输入密码短语

如果你的创建的密钥对设置了密码短语,使用ssh或者sftp命令时,提示手动输入密码短语。

这时候如果是自动化的脚本作业,应该如何写呢?

网上的方案有使用sshpass,但是如果服务器是AIX系统,很不幸,大概率是找不到这个命令的。

ssh.com官网的ssh-add有提及用到密码短语的密钥使用情况。

Keys with Passphrases

If the key being added has a passphrase, ssh-add will run the ssh-askpass program to obtain the passphrase from the user. If the SSH_ASKPASS environment variable is set, the program given by that environment variable is used instead.

Some people use the SSH_ASKPASS environment variable in scripts to provide a passphrase for a key. The passphrase might then be hard-coded into the script, or the script might fetch it from a password vault. However, use of passphrases in this manner does not eliminate the need for proper key lifecycle management and rotation. Instead, we recommend looking at the PrivX On-Demand Access Manager on how to completely eliminate SSH keys in such applications and replace them by short-lived certificates issued on-demand based on centrally managed access policies.

大意就是,可以用SSH_ASKPASS这个环境变量来实现自动输入密码短语。但是,官方不推荐因为这种取巧的方法并不能满足密钥的生命周期管理和轮替。顺便带出另一款产品——PrivX。

我不管,我就用取巧的方法。这里有一个帖子提到如何利用SSH_ASKPASS。

大概如下:

1printf "#!/bin/bash\necho password\n" > /usr/bin/sshpass.sh 2printf "ls -lrt \n quit \n" > /opt/operation.batch 3export SSH_ASKPASS=/usr/bin/sshpass.sh 4setsid sftp unixforum@localhost < operation.batch

可以看到,sshpass.sh不过是将密码硬编码输出。这里有一个关键点,setsid

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )