将 sshpass 更改为更安全的解决方案
change sshpass to a more secure solution
我有一个 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 个问题:
- 如果我使用端口转发从远程网络 运行 这个脚本有多不安全?
- 我可以通过哪些方式使此上传更安全?
谢谢!
就个人而言,我会为每个主机生成一个 SSH 密钥对,然后您就可以完全忘记在 scp 命令中使用密码了。内嵌密码不是问题,但这确实意味着您的密码将记录在该用户的 ~/.bash_history 文件中。
我有一个 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 个问题:
- 如果我使用端口转发从远程网络 运行 这个脚本有多不安全?
- 我可以通过哪些方式使此上传更安全?
谢谢!
就个人而言,我会为每个主机生成一个 SSH 密钥对,然后您就可以完全忘记在 scp 命令中使用密码了。内嵌密码不是问题,但这确实意味着您的密码将记录在该用户的 ~/.bash_history 文件中。