Connecting to a Windows file server from a Linux box

Updated 18 Jan 2013

Gentoo

There are two basic prerequisites for mounting a Windows share on a Gentoo Linux client. First, your kernel must be compiled with cifs support. Second, you must emerge the appropriate packages. The package used to be called mount-cifs, but this package is obsolete. You only need to install net-fs/samba, which will pull in net-fs/cifs-utils and a few other dependencies. The Samba page on the Gentoo Wiki is pretty good.

Since you probably need a user name and password to log in to the Windows share, you should create a credentials file. You don’t want to specify your password on the command line because it will be saved in your .bash_history file and unauthorized users may be able to see it. I created a file called /etc/credentials.txt and set permissions so that only root can see it. The format is:

username=windows_username
password=windows_password

Here is a command line you can use to mount a shared partition on a Windows server:

mount -t cifs //server_name/path_to_share /mnt/mount_point/ -o nosuid,uid=your_username,rw,noexec,credentials=/etc/credentials.txt

Once you get it working, add a line to /etc/fstab so you don’t have to remember that command:

//server_name/path_to_share    /mnt/mount_point    cifs    uid=your_usrname,rw,noexec,credentials=/etc/credentials.txt

By default, the mount.cifs program is not installed suid. Therefore, only root can mount the Windows share. The uid option specifies which user should “own” the files on the Windows share when the sharing server doesn’t provide ownership information. Don’t worry, this does not bypass the Windows permissions on the shared volume!

Red Hat Enterprise Linux 5

For RHEL 5, the only difference is the name of the package that needs to be installed. I installed samba-client and its dependencies. The command-line options and fstab configuration are the same as described above.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s