Novell Cool Solutions

Mount and Access Windows Shares from the Command Line



By:

May 22, 2009 2:23 pm

Reads:9,647

Comments:0

Score:Unrated

Print/PDF

If you have Windows shares and want to access it from Linux, here is the way to access from command line. I am going to explain two different methods to connect to Windows shares.

  1. Connect to share interactively(FTP way of connecting).
  2. Mount the share to a local folder and access it like a local folder.

Method 1: Connect to share/server interactively (FTP way of connecting)

Let say ‘mirage’ is the Windows share name. Here is the command to access the share interactively.

Syntax:

mount  //IP_ADDR_OF_Windows_machine/Sharename -Uusername

Ex:

mount //192.168.1.14/mirage -Uadmin 

In the above example 192.168.1.14 is the IP of the Windows machine and ‘mirage’ is the share name, ‘admin’ is the user name for that share to access. When it prompts for the password, just pass it you will see a commnad prompt like ‘smb: >’. ‘Help’ is the command to list all the supported commands.

The following snapshot shows the list of available commands.

Description of the some of the smbclient commands:

get <remote file name >  [local file name ]

Copy the file called ‘remote file name’ from the share/server to the machine running the smb client. If specified, name the local copy local file name. Note that all transfers in the smbclient are binary.

put <local file name >  [remote file name ]

Copy the file called ‘local file name’ from the machine running the smbclient to the share/server. If specified, name the remote copy remote file name.

open <file name>

Open a remote file and print file ID.

'close fileID

Closes a file explicitly opened by the open command.

Method 2: Mount the share to a local folder and access it

Following are the steps to mount a Windows share to a local folder.

Step 1. Create a local folder

$mkdir test_dir

Step 2. Mount the share using the following command

Note: Pls make sure to run mount and umount commands as root user.

Syntax:

mount -t cifs //Windows_IP/share_name  target_folder_path -o username=user,password=pwd

In the above command, the ‘-t ‘ option is used to specify the type of file system or type of protocol to mount. username should belong to one of the existing users in the Windows machine and he/she should have permissions to access the share.

Ex:

mount -t cifs //192.168.1.14/shared_folder ./test_dir -o username=user,password=abcdef

One can store the credentials in a file and use that file for user authentication. The format of file should be look like:

username=value
password=value

Use the credentials options to specify the credentials file name, as shown in following:

Ex:

mount -t cifs //192.168.1.14/shared_folder ./test_dir  -o credentials=filename

Step 3. Change to the ‘test_dir’ folder. Now you will be able to see the contents of the shared folder

The type of operation you can perform on the share depends on the your access rights for that share. These access rights can be configurable while creating the share.

To unmount the mounted share folder use the following command:

Syntax:

umount mounted_folder_path

Ex:

umount ./test_dir

The following snapshot shows the commands to mount and unmount the shared folder.

0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.
Loading...Loading...

Categories: Uncategorized

0

Disclaimer: This content is not supported by Novell. It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test it thoroughly before using it in a production environment.

Comment

RSS