php - 如何以安全的方式运行 cron? (收到此警告 : "Using a password on the command line interface can be insecure")

标签 php security cron

我使用 cPanel 创建了一个 cronjob。

每隔一段时间它就会运行这个生成备份的 php 文件:

<?php 
include $_SERVER['DOCUMENT_ROOT'].'conectar.php';

$filename='backup_cursos_'.date('d-M-y__H:i:s').'.sql';

$result=exec('mysqldump '.DATABASE.' --password='.PASS.' --user='.USER.' --single-transaction >/home/cursos/backups/'.$filename,$output);

if($output==''){/* no output is good */}
else {/* we have something to log the output here*/}

?>

DATABASEPASSUSER 常量存储在conectar.php 文件中。

每次 cron 运行时我都会收到此警告消息:

Warning: Using a password on the command line interface can be insecure.

我以为在那里添加常量是安全的,所以我的问题是:

如何以安全的方式运行 cron 作业?

最佳答案

参见 Suppress warning messages using mysql from within Terminal, but password written in bash script有关该问题的详细信息。基本上:不要通过命令行而是通过设置提供密码。

关于php - 如何以安全的方式运行 cron? (收到此警告 : "Using a password on the command line interface can be insecure"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45775741/

相关文章:

javascript - XMLHttpRequest 在 PHP 脚本运行时获取数据

javascript - 当任何查看 js 代码的人都可以看到 javascript API key 时,它有什么意义

android - 在手机上恢复已删除的消息和数据

php - 如果使用 PHP 用户的时区发生更改,如何处理存储在数据库中的用户数据

javascript - 如何防止 PHP 游戏从 AJAX 调用中重新实例化

php - preg_replace 密码过滤器

php - 类 stdClass 的对象无法转换为字符串 PHP 问题

perl - 在 Perl 中,用户提供的格式说明符总是安全的吗?

python - 带有 chromedriver 的 Selenium 不会通过 cron 启动

python - 在 Ubuntu 中重新启动崩溃的 Python 脚本?