January 9, 2007

Accessing Windows share from Linux command prompt

Three forms of invocation do not actually mount anything:

mount –h prints a help message;

mount –V prints a version string; and just

mount [-l] [-t type] lists all mounted file systems (of type type).

The option -l adds the (ext2, ext3 and XFS) labels in this listing. See below. Since Linux 2.4.0 it is possible to remount part of the file hierarchy somewhere else.

mount --bind olddir newdir After this call the same contents is accessible in two places.

This call attaches only (part of) a single filesystem, not possible submounts. The entire file hierarchy including submounts is attached a second place using

mount --rbind olddir newdir

Since Linux 2.5.1 it is possible to atomically move a subtree to another place. The call is

mount --move olddir newdir

How do I Access Windows share from Linux command prompt? I would like to be able to access shared folders on Windows machines from my Linux system.

There are two ways. Use command line tool called smbclient or you can mount windows shares the mount command. Another option is use GUI tools. Please refer previous articles about access windows share from Linux:

( a ) Mount Windows share using mount command

This is simple way to share data between windows and linux system. You would like to access MS-Windows share called //windowsserver/sharename by mounting to /mnt/win directory under Linux system. Type the following command (replace username, windows server name, share name and password with actual values):

For most types all the mount program has to do is issue a simple mount(2) system call, and no detailed knowledge of the filesystem type is required. For a few types however (like nfs, smbfs, ncpfs) ad hoc code is necessary. The nfs ad hoc code is built in, but smbfs and ncpfs have a separate mount program. In order to make it possible to treat all types in a uniform way, mount will execute the program /sbin/mount.TYPE (if that exists) when called with type TYPE. Since various versions of the smbmount program have different calling conventions, /sbin/mount.smb may have to be a shell script that sets up the desired call.

# mkdir -p /mnt/win

# mount -t smbfs -o username=winntuser,password=mypassword //windowsserver/sharename /mnt/win

# cd /mnt/win

# ls –l

For the share //windowsserver/sharename to be automatically mounted at every system start (after reboot), insert an option in the file /etc/fstab:

# vi /etc/fstab

Append following line (written in a single line)

//windowserver/share /mnt/win smbfs auto,gid=users,fmask=0664,dmask=0775,iocharset=iso8859-15, credentials=/etc/sambapasswords 0 0

Next create the password file /etc/sambapasswords:
# vi /etc/sambapasswords
Now add following content:
username = winntuser
password = mypassword

Save and close the file. Make sure only root can access your file:
# chown 0.0 /etc/sambapasswords
# chmod 600 /etc/sambapasswords

No comments: