Linux – Mount CIFS Credentials File has Special Character

cifslinuxmount

I'm having trouble mounting a share on my XenServer (5.6 FP1). From the command line I try:

mount.cifs //server/share /mnt/share -o credentials=credfile

The contents of credfile is:

username=Administrator
password=What@zR\!p3s

When I run the above mount command I get "Access Denied". However if I run the following command it works:

mount.cifs //server/share /mnt/share -o username=Administrator,password=What@zR\!p3s

Please note the "\" is to escape the bang and I've tried this with and without it in the credentials file. Any suggestions?

Best Answer

I have the same problem because my password contain comma symbol (i.e. "PASS,WORD"):

$ sudo mount -t cifs -o domain=mydomain,username=myuser,password=PASS,WORD //server/share localfolder
mount error(22): Invalid argument
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

At first, you should try enable verbose mode (--verbose option):

$ sudo mount -t cifs -o domain=mydomain,username=myuser,password=PASS,WORD //server/share localfolder --verbose
mount.cifs kernel mount options: ip=172.30.91.137,unc=\\server\share,WORD,user=myuser,,domain=mydomain,pass=********

Here I see my problem. Comma breaks all stuff. Solution is use credential file. What is written in man mount.cifs:

credentials=filename specifies a file that contains a username and/or password and optionally the name of the workgroup. The format of the file is:

          username=value
          password=value
          domain=value

This is preferred over having passwords in plaintext in a shared file, such as /etc/fstab. Be sure to protect any credentials file properly.

Create this file any way you like:

$ cat > cifs.credo
username=myuser
password=PASS,WORD
domain=mydomain

and use (--verbose can be omitted)

$ sudo mount -t cifs -o credentials=path/to/cifs.credo //server/share localfolder --verbose
mount.cifs kernel mount options: ip=172.30.91.137,unc=\\server\share,user=myuser,,domain=mydomain,pass=********

No problem with password.