How Do I Access Windows Shares From BASH?

First you need to have samba and cifs-utils installed:

sudo apt-get install samba cifs-utils

Then use a Bash script to mount windows share folder in linux using samba:

$ mkdir /mnt/smb

$ touch smb.sh

chmod +x smb.sh

$ vi smb.sh

Write the following into the smb.sh file using vi:

#/bin/bash



SERVER_IP="192.168.1.1"

SHARE_NAME="c$"

USERNAME="samba user name"

PASSWD="samba password"

DOMAIN="domain"


mount.cifs //$SERVER_IP/$SHARE_NAME /mnt/smb/ -o username=$USERNAME,password=$PASSWD,dom=$DOMAIN

Finally run the script to mount your Windows share and cd into the share:

./smb.sh

$ cd /mnt/smb/

Another method that seems to me to be more straight forward and easier: It involves creating the mount point, editing fstab, and then mounting all filesystems in fstab with one command.

Make the folder: sudo mkdir /mnt/myDirectory

Edit the fstab: sudo vi /etc/fstab

Append the following to the fstab file:

//server/Share /mnt/myDirectory cifs domain=myDomain,username=myUserName,password=myPassword 0 0

Be sure to fill in all the appropriate information in place of those placeholders. And save the fstab file with wq for "write and quit."

Finally mount all the file systems listed in fstab:

sudo mount -a

Now you can verify that the share is available with:

ls /mnt/myDirectory

And you should see the files in the top level directory of the Windows Share.


Looks like this is an old article, but still very relevant. I found since the WannaCry ransomware (May 2017) issue many Windows shares refuse to use the old SMB V1.

This is what I ended up having to do
I had the following installed:

sudo apt install samba-common samba-common-bin cifs-utils

Then add lines under [global] - vi /etc/samba/smb.conf

server min protocol = SMB2_10
client min protocol = SMB2
client max protocol = SMB3

this then allowed the following command:

mount -t cifs -o vers=2.1 -o username=<username>,sec=ntlmssp //server/path /mnt/smb