我有一个包含以下函数的 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)
我有两个问题:
- 如果我使用端口转发从远程网络运行此脚本有多不安全?
- 我可以通过哪些方式使上传更安全?
谢谢!
最佳答案
就个人而言,我会为每个主机生成一个 SSH key 对,然后您就可以完全忘记在 scp 命令中使用密码了。内联密码不是问题,但这确实意味着您的密码将记录在该用户的 ~/.bash_history 文件中。
关于python - 将 sshpass 更改为更安全的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46265684/