我正在维护一个异构的mac和linuxnetworking,所以我决定创build一个perl脚本来统一跨机器的安装策略。
其实,我已经有一个工作Perl脚本,但是,密码似乎是我不喜欢的命令行的一部分:
mount_smbfs -d 755 -f 755 //username_here:[email protected]/cifs_share
尝试读取mount_smbfs和nsmb.conf的手册页,但我仍然困惑如何前进。
我的机器是雪豹,豹和狮子机器。
比SvenW提出的更安全的解决scheme,更符合苹果公司的做法,就是将密码添加到钥匙串中。 这里是你如何做一个法新社共享(我假设你所需要做的是改变-r选项指定的协议,但我没有现在用SMBtesting这个可能性;请注意,空格在“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"
以下是安全命令手册页的相关部分:
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, eg "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.
同样的事情应该适用于SMB共享,但请注意,匹配钥匙串条目的机制是相当特殊的(例如,要求在协议名称中有奇怪的空白),所以您需要testing并准确地说明如何存储密码。 当我第一次使用这种方法时,我发现为了让参数正确,它首先通过GUI在密钥链中创build密码(即,将共享装入Finder并勾选该框以将authentication证书保存到钥匙串),并通过检查钥匙串中的结果条目来反向工作。
正如SvenW所指出的那样,钥匙链需要解锁才能使用这种方法,但这种情况应该在用户login时自动发生,根据您的描述不应该成为问题。 我也想确认Kerberos的确在10.5和10.6中工作,但在10.7中是有问题的。
把一个〜/ Library / Preferences / nsmb.conf文件放入你想要挂载的用户的主目录下:
[myserver.com] username=username_here password=password_here
之后,你可以简单地做
mount -t smbfs -o -d=755,-f=755 //myserver.com/cifs_share /mountpoint
对我来说,这是看我的钥匙链里面的东西
并与我的auto_smb地图匹配…
/../Volumes/ServiceData -fstype=smbfs,soft ://home._smb._tcp.local/ServiceData