mount.cifs fails (Error 2, no such file or directory) with credentials file, while -o username,password succeeds

8,216

A friend helped me figure it out - I was in the directory containing my credentials while running the command, but I needed to provide the absolute path. I'm not sure whether it has to do with the fact that my home directory is in /mnt, but regardless, the following approach succeeds:

$ sudo mount -t cifs -o credentials=/mnt/path/to/mycreds //mydomain/share/Users/me /mnt/mydir
# Success
Share:
8,216

Related videos on Youtube

John D
Author by

John D

Updated on September 18, 2022

Comments

  • John D
    John D over 1 year

    Long time, first time. I'm running RHEL 7.2 (Maipo), and unable to mount a NAS using credentials stored in a file. The directory mounts successfully if I pass username and password directly in the command line, but I'd like to use a credentials file instead for security reasons

    $ sudo mount -t cifs -o username=myname,password=mypassword //mydomain/share/Users/me /mnt/mydir
    # Success
    $ printf "username=myname\npassword=mypassword\n" >> mycreds
    $ sudo mount -t cifs -o credentials=mycreds //mydomain/share/Users/me /mnt/mydir
    # error 2 (No such file or directory) opening credential file mycreds
    

    The password only contains alphanumeric characters, so it's not an issue with special characters.

    Permissions on the credentials file are currently set as follows. I started out as the file owner, but that didn't work either.

    $ ls -l mycreds
    # -rwSr-xr-x. 1 root root 40 Mar 19 18:23 mycreds
    

    mount.cifs --version returns mount.cifs version: 6.2

    I haven't added any lines to /etc/fstab while testing mount. I'd like to verify it works from command line first.

    Let me know if more information would help!

    • roaima
      roaima about 6 years
      Remove group and other permissions from the credentials file. Otherwise your security is (at best) no better than providing a username and password on the mount command line. Use chmod u=rw,go= mycreds
    • roaima
      roaima about 6 years
      I have always understood that the credentials file required a tuple of { username, password, domain }, where domain is your workgroup.