我的密码在配置文件中。如何防止系统上其他用户读取?

我的密码在配置文件中。如何防止系统上其他用户读取?

我正在尝试使用ssmtp命令行邮件应用程序这个答案

其中一个步骤是将我的邮件账户密码放在一个文件中/etc/ssmtp/ssmtp.conf。由于该文件对所有用户都有读取权限,因此它破坏了我的密码的保密性。

如何克服这个问题?我尝试删除组和其他人的读取权限,但 ssmtp 不再起作用。

答案1

答案包含在示例 ssmtp.conf 文件中 - 内容如下(取自http://wiki.debian.org/sSMTP(英文):

#### VERY IMPORTANT !!! If other people have access to this computer
# Your GMAIL Password is left unencrypted in this file
# so make sure you have a strong root password, and make sure
# you change the permissions of this file to be 640:
# chown root:mail /etc/ssmtp/ssmtp.conf
# chmod 640 /etc/ssmtp/ssmtp.conf"

答案2

我认为最好的方法是为 ssmtp 创建技术用户。这里有一个不错的教程https://wiki.freebsd.org/SecureSSMTP

以下是其中的摘录,步骤 4、5、6、8、9 就是您要找的(根据您使用的 Linux 发行版,路径可能有所不同,我现在已经针对 Debian 进行了定制):

[步骤4]创建 ssmtp 用户:

sudo useradd -g nogroup -M -s /bin/false -c "sSMTP pseudo-user" ssmtp

这会将 ssmtp 用户保留在 nogroup 组中,不允许基于密码的登录(-h)。

[步骤 5]在 sSMTP 配置目录上设置正确的所有者和权限。我们设置 setuid 位(请参阅 chmod(1) 以确保目录中的新文件也归用户 ssmtp 所有:

cd /etc/ssmtp
chown ssmtp:wheel .
chmod 4750 .

[步骤 6]使用正确的权限创建 sSMTP 配置文件:

sudo cp ssmtp.conf.sample ssmtp.conf
sudo chown ssmtp:wheel . ssmtp.conf
sudo chmod 640 ssmtp.conf

[步骤 8]使 ssmtp 用户拥有 ssmtp 可执行文件并将其标记为 SUID:

chown ssmtp:nogroup /usr/sbin/ssmtp
chmod 4555 /usr/sbin/ssmtp

[第 9 步]以非特权用户身份运行一些测试:

$ cat /etc/ssmtp/ssmtp.conf
cat: /etc/ssmtp/ssmtp.conf: Permission denied
$ sendmail [email protected] < /etc/rc.conf

答案3

尝试ssmtp以普通用户身份调用并指定自定义配置文件位置。

来自的手册页ssmtp(8)

-Cfile Use alternate configuration file.

将您的配置文件放在主目录中的安全位置,不给其他人读取权限。然后ssmtp像这样运行:

user@host:~$ ssmtp -C/path/to/somesecuredir/ssmtp.conf [options]

相关内容