将sshpass更改为更安全的解决方案

时间:2017-09-17 15:19:16

标签: python ssh scp

我有一个包含以下函数的python脚本:

def upload2server(file):
    host_name = 'example.ex.am.com'
    port_num = '432'
    user_name = 'user'
    password = 'passw'
    web_path = '/example/files/'
    full_webpath = user_name + '@' + host_name + ':' + web_path + args.key
    pre_command = 'sshpass -p "' + password + '" scp -P' + ' ' + port_num + ' ' 

    scp_comm = pre_command + file + ' ' + full_webpath 

    os.system(scp_comm)

我有2个问题:

  1. 如果我使用端口转发从远程网络运行此脚本有多不安全?
  2. 我可以通过哪些方式使上传更加安全?
  3. 谢谢!

1 个答案:

答案 0 :(得分:1)

就个人而言,我会为每个主机生成SSH密钥对,然后您可以完全忘记在scp命令中使用密码。内联密码不是问题,但它确实意味着您的密码将记录在该用户的〜/ .bash_history文件中。

相关问题