command line smbfs mounts

I got this working and thought it worth putting down here for my own memory, and perhaps to help someone else.

It’s possible to mount Windows (a/k/a CIFS or samba) shares on the command line. You need to create a .nsmbrc file (not unlike a .netrc file), and populate it like the one below. This is handy if you want to copy files to a file server that gets backed up regularly, but doesn’t require you to be logged in to or have it mounted.

To hash the passwords, use smbutil:

bash-2.05a$ smbutil crypt password
$$178465324253e0c07

Then replace the uppercased bits with stuff that really exists, and replace the password hashes with the ones you made.

bash-2.05a$ more .nsmbrc
[default]
workgroup=WORKGROUP
username=USERNAME
[HOST:USERNAME:SHARE]
password=$$password
[HOST:USERNAME:SHARE2]
password=$$password
[HOST2:USERNAME:SHARE]
password=$$password

And then just mount your filesystems as needed: no need to use su, even.

bash-2.05a$ df -k
Filesystem              1K-blocks     Used    Avail Capacity  Mounted on
/dev/disk0s9             78143056 12793924 65093128    16%    /
devfs                          95       95        0   100%    /dev
fdesc                           1        1        0   100%    /dev
                       512      512        0   100%    /.vol
automount -fstab [404]          0        0        0   100%    /Network/Servers
automount -static [404]         0        0        0   100%    /automount

Now you don’t see /Volumes/www . . . . .

bash-2.05a$ mount_smbfs //pdb2@mars/www /Volumes/www/
kextload: extension /System/Library/Extensions/smbfs.kext is already loaded
Filesystem              1K-blocks     Used    Avail Capacity  Mounted on
/dev/disk0s9             78143056 12793924 65093128    16%    /
devfs                          95       95        0   100%    /dev
fdesc                           1        1        0   100%    /dev
                       512      512        0   100%    /.vol
automount -fstab [404]          0        0        0   100%    /Network/Servers
automount -static [404]         0        0        0   100%    /automount
//PDB2@MARS/WWW          26627736  1736436 24891300     6%    /Volumes/www

Now you do . . .