0

In order to pass a password in a shell script you will have to write:

sudo mount -t cifs -o password=asdasd,username=mc007,uid=1000 //192.168.1.105/cfmaster/ /PMaster/projects/x4mm/win

But there are situations you don't want to use sudo (build-scripts,...).

And so if you don't use sudo, the command will abort with:

only root can use "--options" option

Now, how can one mount network share with password from within a non-interrupting shell script?

thanks

edwinksl
  • 23,789
xamiro
  • 555
  • What are these things you "can't or don't want"? – muru Oct 09 '16 at 17:42
  • simple as that : having shell scripts asking for passwords! – xamiro Oct 09 '16 at 17:49
  • Does the location of the share vary? If not, you could specify the mount options in /etc/fstab. Or write a script for which you add a NOPASSWD rule in sudoers. – muru Oct 09 '16 at 17:54
  • Hi, thanks. Yes it varies. Its part of a build-chain and the mounts are all temporarily (ie: no fstab wanted or needed). So, but you say there is way to enable options for mount for non-sudoers? Mhmm, i don't understand why this must be so complicated but ok, i will google now for NOPASSWD rule. whatever this is. Thanks again! – xamiro Oct 09 '16 at 17:59
  • oh dear, was looking at that NOPASSWD thing: super complicated or at least hard to understand. a no go, just want to mount a windows share, jeez. – xamiro Oct 09 '16 at 18:04
  • 1
    Huh. You're talking as if mounting a Windows password in a script is for a build chain is something everyday users do. :P http://askubuntu.com/a/159009/158442 Doesn't look "super complicated" to me. – muru Oct 09 '16 at 18:07
  • ok, thanks Muru! Still, this is pretty hard to communicate/document for our non experts. Things could be easy as on win/osx where you don't needs this sort of 'hacks' – xamiro Oct 09 '16 at 18:10
  • If you say so. What would you do in Windows or OSX? – muru Oct 09 '16 at 18:11
  • pass the password in the script without doing any big research or editing complicated files with root permissions. On win you the "net use" command, on osx something similar. However, pretty shocking to me ;-) – xamiro Oct 09 '16 at 18:13
  • 1
    If all you want to is pass the password in the script, see http://askubuntu.com/a/585183/158442. – muru Oct 09 '16 at 18:14

1 Answers1

0

As mentioned in the comments, user 'muru' suggests to look at How do I run specific sudo commands without a password?. After researching it seems the only official supported way to mount a password protected windows share from within a script.

It needs you to be a tech savy, and it needs you to alter system files with root permissions.

xamiro
  • 555