运行 drush 时防止在命令行历史记录中记录敏感数据
Prevent logging sensitive data in command line history when running drush
我正在尝试使用 drush 命令安装 Drupal:
drush -y -v site-install standard --db-url=mysql://${db_user}:${db_pass}@${db_host}:${db_port}/${db_name} --account-name=${DRUPAL_ADM_USER} --account-pass=${DRUPAL_ADM_PASS} --locale=${LANG} --site-name=\"${DRUPAL_SITE_NAME}\";
它正在使用 MySQL 数据库,我必须在 db-url 选项,但我不希望此敏感信息出现在我的控制台历史记录中。
我需要一些帮助来隐藏这些信息。提前致谢。
这里有 2 个命令可能有助于防止敏感数据被记录到您的命令行历史记录中:
在 运行 drush site-install
之前使用 read
命令提示输入密码。
# Read standard input and store it into db_pass
# -s prevents echoing the input.
# -p <string> outputs the string without a trailing newline before.
read -s -p "Password : " db_pass
您还可以使用源或点运算符(source
或 .
,从外部文件中 source
变量,但这意味着信息以普通格式存储文本(或最多加密),因此应首先考虑为此类文件设置适当的权限。用法:
# Create ~/install.conf and make it initialize db_user
echo 'db_user=foobar' > ~/install.conf
# Execute ~/install.conf commands in the current shell context.
. ~/install.conf
# Test : outputs 'foobar'
echo ${db_user}
典型的安装脚本使用这两种方法,在您的情况下,如果除 db_pass 之外的所有变量都为 stored/initialized in ~/install.conf
,你会做这样的事情:
#!/bin/bash
. ~/install.conf
read -p 'Press [ Enter ] to begin installation'
while [ -z "$db_pass" ] || [ "$db_pass" != "$check" ]; do
read -s -p "Password: " db_pass && echo
read -s -p "Confirm Password : " check && echo
done
drush -y -v site-install standard --db-url=mysql:\//${db_user}:${db_pass}@${db_host}:${db_port}/${db_name} --account-name=${DRUPAL_ADM_USER} --account-pass=${DRUPAL_ADM_PASS} --locale=${LANG} --site-name=\"${DRUPAL_SITE_NAME}\";
我正在尝试使用 drush 命令安装 Drupal:
drush -y -v site-install standard --db-url=mysql://${db_user}:${db_pass}@${db_host}:${db_port}/${db_name} --account-name=${DRUPAL_ADM_USER} --account-pass=${DRUPAL_ADM_PASS} --locale=${LANG} --site-name=\"${DRUPAL_SITE_NAME}\";
它正在使用 MySQL 数据库,我必须在 db-url 选项,但我不希望此敏感信息出现在我的控制台历史记录中。
我需要一些帮助来隐藏这些信息。提前致谢。
这里有 2 个命令可能有助于防止敏感数据被记录到您的命令行历史记录中:
在 运行
drush site-install
之前使用read
命令提示输入密码。# Read standard input and store it into db_pass # -s prevents echoing the input. # -p <string> outputs the string without a trailing newline before. read -s -p "Password : " db_pass
您还可以使用源或点运算符(
source
或.
,从外部文件中source
变量,但这意味着信息以普通格式存储文本(或最多加密),因此应首先考虑为此类文件设置适当的权限。用法:# Create ~/install.conf and make it initialize db_user echo 'db_user=foobar' > ~/install.conf # Execute ~/install.conf commands in the current shell context. . ~/install.conf # Test : outputs 'foobar' echo ${db_user}
典型的安装脚本使用这两种方法,在您的情况下,如果除 db_pass 之外的所有变量都为 stored/initialized in ~/install.conf
,你会做这样的事情:
#!/bin/bash
. ~/install.conf
read -p 'Press [ Enter ] to begin installation'
while [ -z "$db_pass" ] || [ "$db_pass" != "$check" ]; do
read -s -p "Password: " db_pass && echo
read -s -p "Confirm Password : " check && echo
done
drush -y -v site-install standard --db-url=mysql:\//${db_user}:${db_pass}@${db_host}:${db_port}/${db_name} --account-name=${DRUPAL_ADM_USER} --account-pass=${DRUPAL_ADM_PASS} --locale=${LANG} --site-name=\"${DRUPAL_SITE_NAME}\";