在 mac 中安装受密码保护的 cifs 共享的安全方法

ica*_*pan 9 mac mount server-message-block cifs mac-osx

我正在维护一个 mac 和 linux 的异构网络,所以我决定创建一个小 perl 脚本来统一跨机器的安装策略。

实际上,我已经有一个可以工作的 perl 脚本,但是,密码似乎是我不喜欢的命令行的一部分:

 mount_smbfs -d 755 -f 755 //username_here:password_here@myserver.com/cifs_share
Run Code Online (Sandbox Code Playgroud)

尝试阅读 mount_smbfs 和 nsmb.conf 的手册页,但我仍然对如何前进感到困惑。

我的机器是雪豹,豹和狮子机器。

Joe*_*oll 7

比 SvenW 提出的更安全的解决方案,并且更符合 Apple 的做事方式,是将密码添加到钥匙串中。这是您如何为 AFP 共享执行此操作(我假设您需要做的就是更改 -r 选项指定的协议,但我现在无法使用 SMB 进行测试;请注意,空格在“afp”中是有意且必要的,我只在 10.6 环境中使用过):

sudo security add-internet-password -a "username_here" -D "Network Password" -r "afp " -l "cifs_share" -s "myserver.com" -p "cifs_share" -w "password_here"  -T "/System/Library/CoreServices/NetAuthAgent.app/Contents/MacOS/NetAuthAgent"
Run Code Online (Sandbox Code Playgroud)

以下是security命令手册页的相关部分:

add-internet-password [-h] [-a account] [-s server] [-w password] [options...] [keychain]
            Add an internet password item.

            -a account      Specify account name (required)
            -c creator      Specify item creator (optional four-character code)
            -C type         Specify item type (optional four-character code)
            -d domain       Specify security domain string (optional)
            -D kind         Specify kind (default is "application password")
            -j comment      Specify comment string (optional)
            -l label        Specify label (if omitted, service name is used as default label)
            -p path         Specify path string (optional)
            -P port         Specify port number (optional)
            -r protocol     Specify protocol (optional four-character SecProtocolType, e.g. "http", "ftp ")
            -s server       Specify server name (required)
            -t authenticationType
                            Specify authentication type (as a four-character SecAuthenticationType, default is "dflt")
            -w password     Specify password to be added
            -A              Allow any application to access this item without warning (insecure, not recommended!)
            -T appPath      Specify an application which may access this item (multiple -T options are allowed)
            -U              Update item if it already exists (if omitted, the item cannot already exist)

            By default, the application which creates an item is trusted to access its data without warning.  You can remove this default access
            by explicitly specifying an empty app pathname: -T "". If no keychain is specified, the password is added to the default keychain.
Run Code Online (Sandbox Code Playgroud)

同样的事情应该适用于 SMB 共享,但请注意匹配钥匙串条目的机制非常特殊(例如,要求在协议名称中使用奇怪的空格),因此您需要测试并准确存储密码的方式。当我第一次使用这种方法时,我发现为了使参数正确,它有助于首先通过 GUI 在钥匙串中创建密码(即在 Finder 中安装共享并勾选框以将身份验证凭据保存到钥匙串)并通过检查钥匙串中的结果条目向后工作。

正如 SvenW 所指出的,需要解锁钥匙串才能使这种方法起作用,但这应该会在用户登录时自动发生,并且根据您的描述应该不会有问题。我还想确认 Kerberos 在 10.5 和 10.6 中确实有效,但在 10.7 中存在问题。


Sve*_*ven 6

将包含以下内容的 ~/Library/Preferences/nsmb.conf 文件放入要进行挂载的用户的主目录中:

[myserver.com]
username=username_here
password=password_here
Run Code Online (Sandbox Code Playgroud)

之后,你可以简单地做

mount -t smbfs -o -d=755,-f=755 //myserver.com/cifs_share /mountpoint 
Run Code Online (Sandbox Code Playgroud)