Skip to main content
Question

Open SMB share as non-root user from command line without "Connecting to" prompt?


Forum|alt.badge.img+10

I've got a script that's running as a non-root user that needs to be able to open an SMB share. As it's not root, it can't create a folder in /Volumes, so I need to use "open" rather than "mount".

However in recent macOS versions there's a prompt saying "Connecting to" such and such a server.

Is there any command line switch which can bypass that prompt?

Thanks,
Dan Jackson (Senior ITServices Technician)
Long Road Sixth Form College
Cambridge, UK.

2 replies

Hugonaut
Forum|alt.badge.img+15
  • Esteemed Contributor
  • 574 replies
  • February 1, 2019

have you tried

mount_smbfs //$Uname:$Passw@$SambaShare $Location

I haven't actually done this but worked off the Man Page - 'man mount_smbfs'

NAME
     mount_smbfs -- mount a shared resource from an SMB file server

SYNOPSIS
     mount_smbfs [-N] [-o options] [-d mode] [-f mode] [-h] [-s] [-v]
                 //[domain;][user[:password]@]server[/share] path

DESCRIPTION
     The mount_smbfs command mounts a share from a remote server using
     SMB/CIFS protocol.

Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • February 1, 2019

@DanJ_LRSFC Try this:

#!/bin/bash

# SMB location here
serverShare="server.yourcorp.com/share"

# Allow unknown servers
# https://support.apple.com/en-us/HT207112
# This should really be done via a Configuration Profile
defaults write /Library/Preferences/com.apple.NetworkAuthorization AllowUnknownServers -bool YES
sleep 5

# Mount the drive as john_doe while logged in as john_doe
loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
path="smb://${loggedInUser}:@${serverShare}"
/usr/bin/osascript -e "mount volume "$path""

exit 0

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings