# Script to Create Sharing Only User Account on Mac

Organizations may need to share files and folders on devices with other users remotely, but they may want to restrict access to the device settings. Enterprises can set up sharing only user accounts on devices to accomplish this. However, creating an account manually on each device is a tedious task. Hexnode allows you to create sharing only user accounts remotely on macOS devices by [executing custom scripts](https://www.hexnode.com/mobile-device-management/help/how-to-run-scripts-on-mac-using-hexnode-mdm/).

Scripting Language – Bash

File extension – .sh

 Disclaimer: 
The Sample Scripts provided below are adapted from third-party Open-Source sites.

 

Create a sharing-only user account
----------------------------------

You can deploy the script given below to create a sharing-only user account on macOS devices. The script also allows you to customize the account by adding display names, profile pictures, and so on.

Script to create a sharing only user account on Mac

\#!/bin/sh # Create a new user with the username Sharing user sudo dscl . create /Users/Sharing\\ user # Give the display name of the user as David sudo dscl . create /Users/Sharing\\ user RealName "David" # (Optional) Add a password hint sudo dscl . create /Users/Sharing\\ user hint "123456" # (Optional) Set a profile picture. sudo dscl . create /Users/Sharing\\ user picture "/Provide path to the image.png" # Replace “123456” with the required password for the user account. sudo dscl . passwd /Users/Sharing\\ user 123456 # Set the unique ID for the user. Provide an ID which is not already used. sudo dscl . create /Users/Sharing\\ user UniqueID 550 # Set the Group ID for the user sudo dscl . create /Users/Sharing\\ user PrimaryGroupID 20 # Deny shell access for the user sudo dscl . create /Users/Sharing\\ user UserShell /usr/bin/false # No home directory for the user sudo dscl . create /Users/Sharing\\ user NFSHomeDirectory /dev/null 

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

  \#!/bin/sh 

\# Create a new user with the username Sharing user 

sudo dscl . create /Users/Sharing\\ user

\# Give the display name of the user as David 

sudo dscl . create /Users/Sharing\\ user RealName "David"

\# (Optional) Add a password hint 

sudo dscl . create /Users/Sharing\\ user hint "123456"

\# (Optional) Set a profile picture. 

sudo dscl . create /Users/Sharing\\ user picture "/Provide path to the image.png"

\# Replace “123456” with the required password for the user account. 

sudo dscl . passwd /Users/Sharing\\ user 123456

\# Set the unique ID for the user. Provide an ID which is not already used. 

sudo dscl . create /Users/Sharing\\ user UniqueID 550

\# Set the Group ID for the user 

sudo dscl . create /Users/Sharing\\ user PrimaryGroupID 20

\# Deny shell access for the user 

sudo dscl . create /Users/Sharing\\ user UserShell /usr/bin/false

\# No home directory for the user 

sudo dscl . create /Users/Sharing\\ user NFSHomeDirectory /dev/null 

   

 

  

 Notes:- While writing the username, use a backslash \\ before inserting space to prevent the shell interpreter from interpreting space as a separator and assuming two words as different arguments. E.g., for displaying Sharing user, write the code as `Sharing\ user`.
- The Unique ID assigned to the first account on the system is 501. Choose a unique number for the ID.
- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.