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.
- Connect to share interactively(FTP way of connecting).
- 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.
mount //IP_ADDR_OF_Windows_machine/Sharename -Uusername
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.
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
Step 2. Mount the share using the following command
Note: Pls make sure to run mount and umount commands as root user.
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.
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:
Use the credentials options to specify the credentials file name, as shown in following:
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:
The following snapshot shows the commands to mount and unmount the shared folder.
Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).
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, test, test before you do anything drastic with it.