在 UNC 路径中传递 UNC 用户名和密码

Kva*_*vad 30 windows authentication

是否可以在 UNC 路径中传递 UNC 用户名和密码?

类似于 FTP 和 SMB 对此的支持方式:

smb://user:pass@destination.com/share
ftp://user:pass@destination.com/share
Run Code Online (Sandbox Code Playgroud)

我正在尝试获得对 DFS 路径的(非域 PC)服务访问权限。

有没有其他方法可以解决这个问题?我可以将 PC 绑定到域并以域用户身份运行服务,但如果我使用的是 Linux 呢?

use*_*686 22

在 Windows 上,不能将凭据放在 UNC 路径中。您必须使用net userunas /netonly或 当 Windows 询问时提供它们。

您还可以使用cmdkey /add:或使用 C 中的 CredWrite() 函数将密码存储为“域凭据” ,这两者都相当于在 Windows 中选中“记住密码”框。

在 Linux 上,这取决于程序。

  • GNOME 的 Gvfs 接受该user@host语法,但似乎完全忽略了密码。(但是,您可以事先将其存储在 GNOME Keyring 中。)

  • smbclient使用与 Windows 相同的 UNC 语法;但是,它有一个--authentication-file选项,可以从中读取凭据。

  • 上面的两个程序都使用libsmbclient,并且可以使用 Kerberos 身份验证而不是密码: runkinit user@YOUR.DOMAIN和 use smbclient -k //host/share。这比密码验证更安全。

请注意,将密码放入 URI 已被弃用,您不应依赖于任何地方都支持它。

  • @AlexisWilke [RFC 1738 § 3.3](https://tools.ietf.org/html/rfc1738#section-3.3) 开始时不允许在 HTTP 中使用它们,[RFC 2396 § 3.2.2](https://tools. ietf.org/html/rfc2396#section-3.2.2) 有一个更一般的“不推荐”,和 [RFC 3986 § 3.2.1](https://tools.ietf.org/html/rfc3986#section-3.2 .1) 说“不推荐在 userinfo 字段中使用“user:password”格式”。 (2认同)

uSl*_*ckr 17

您可以使用 将“驱动器”映射到 UNC 路径net use。未来的访问应该共享现有的连接

Net Use \\yourUNC\path /user:uname password
Run Code Online (Sandbox Code Playgroud)

注意:您不需要指定驱动器号