简体   繁体   English

如何在数据库中安全保存SSH凭据?

[英]How to save SSH credentials secure in database?

I have a PHP script which connects via SFTP to servers to get data from there. 我有一个PHP脚本,该脚本通过SFTP连接到服务器以从那里获取数据。 That's a necessary thing for my project. 这对我的项目来说是必要的。

But how to store the credentials to this servers in my MYSQL-database? 但是,如何将凭据存储到我的MYSQL数据库中的该服务器上? I don't want to store a SSH-password as plaintext, but I nearly have to, because otherwise the script can't connect? 我不想将SSH密码存储为纯文本格式,但是我几乎必须这样做,因为否则脚本无法连接? Is this true or is there another, secure way? 这是真的还是另外一种安全的方法?

Snippet of my script: 我的脚本片段:

while($row = mysqli_fetch_assoc($servers)) {
  $srvip = $row["ip"];
  $srvuser = $row["user"];
  $srvpassword = $row["password"];
  $file = file_get_contents('ssh2.sftp://' . $srvuser . ':' . $srvpassword . '@' . $srvip . ':22/files/data.txt');
}

Why not use MySQLs encryption options then you can decrypt the password when you run your initial MySQL query? 为什么不使用MySQL的加密选项,然后在运行初始MySQL查询时可以解密密码?

https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html Don't know if its applicable to your application but thats the way i'd go with it? https://dev.mysql.com/doc/refman/8.0/zh-CN/encryption-functions.html不知道它是否适用于您的应用程序,但这就是我的选择方式吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM