Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to pass the UNC username and password within a UNC path?

Similar to how FTP and SMB support this:


I am trying to get a (non domain PC) service access to a DFS path.

Is there another way around this? I could bind the PC to the domain and run the service as a domain user but what if I was using Linux?

share|improve this question
up vote 14 down vote accepted

On Windows, you cannot put credentials in UNC paths. You must provide them using net use, runas /netonly, or when asked by Windows. (If you have some programming skills, you can store the SMB password as a "domain credential" using CredWrite(), which is 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 user@YOUR.DOMAIN 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.

share|improve this answer
Do you have a reference in regard to "putting passwords into URIs is deprecated"? – Alexis Wilke Mar 11 '13 at 4:23
@AlexisWilke RFC 1738 § 3.3 started by not allowing them in HTTP, RFC 2396 § 3.2.2 had a more general "not recommended", and RFC 3986 § 3.2.1 says "Use of the format "user:password" in the userinfo field is deprecated". – grawity Mar 11 '13 at 11:05

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

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

Note: you do not need to specify a drive letter

share|improve this answer

I think the user name and password has to be passed to the server for authentication first before any file access can be done, so the code handling the SMB connection has to be able to parse and extra the user name and password from the URL. You'll have to check if that code supports this format or not.

If it doesn't, you can mount that SMB share through SAMBA and direct your program to use that "local" path. You can put the mount into fstab and use a SAMBA password file to supply the user credentials. Remember to set the correct permissions to the password file so normal users can't read it.

Note that it is bad practice to store passwords in clear text in configuration files, so even if your program can handle password in URL, you should consider the mounted share method.

share|improve this answer
Is fstab not a "clear text configuration file"? – grawity Oct 10 '11 at 11:41
Yes, but in fstab you refer to the password file instead of including the password directly. Then you can secure the password file by changing the owner to root and the mode to 400. – Oct 10 '11 at 13:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .