Passing UNC username and password within a UNC path

On Windows, you cannot put credentials in UNC paths. You must provide them using net use, runas /netonly, or when asked by Windows.

You can also store the password as a "domain credential" using cmdkey /add:, or using the CredWrite() function in C, both of which are equivalent to checking the "Remember password" box in Windows.

On Linux, it depends on the program.

  • GNOME's Gvfs accepts the user@host syntax, but appears to completely ignore the password. (However, you can store it in GNOME Keyring beforehand.)

  • smbclient uses the same UNC syntax as Windows; however, it has an --authentication-file option from which credentials could be read.

  • Both programs above are using libsmbclient, and can use Kerberos authentication instead of passwords: run kinit [email protected] and use smbclient -k //host/share. This is more secure than password authentication.

Note that putting passwords into URIs is deprecated, and you should not rely on it being supported anywhere.


You can map a "drive" to the UNC path using net use. Future accesses should share the existing connection

Net Use \\yourUNC\path /user:uname password

Note: you do not need to specify a drive letter