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

bub*_*ble 5 permissions

我正在尝试ssmtp按照此答案中的建议用作我的命令行邮件应用程序。

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

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

Cli*_*ten 7

答案包含在示例 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"
Run Code Online (Sandbox Code Playgroud)


小智 5

我认为最好的方法是为 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
Run Code Online (Sandbox Code Playgroud)

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

【第五步】在sSMTP配置目录上设置正确的属主和权限。我们设置 setuid 位(请参阅 chmod(1) 以确保目录中的新文件也将由用户 ssmtp 拥有:

cd /etc/ssmtp
chown ssmtp:wheel .
chmod 4750 .
Run Code Online (Sandbox Code Playgroud)

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

sudo cp ssmtp.conf.sample ssmtp.conf
sudo chown ssmtp:wheel . ssmtp.conf
sudo chmod 640 ssmtp.conf
Run Code Online (Sandbox Code Playgroud)

【步骤8】制作ssmtp用户拥有的ssmtp可执行文件并标记为SUID:

chown ssmtp:nogroup /usr/sbin/ssmtp
chmod 4555 /usr/sbin/ssmtp
Run Code Online (Sandbox Code Playgroud)

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

$ cat /etc/ssmtp/ssmtp.conf
cat: /etc/ssmtp/ssmtp.conf: Permission denied
$ sendmail john@example.com < /etc/rc.conf
Run Code Online (Sandbox Code Playgroud)