Print this article Edit this article

Mounting Home Directory on a Linux Operating System

Please note that this article is customized for self-managed Ubuntu-based Linux operating systems. If you use a self-managed RPM-based (RedHat, CentOS, etc.) distro, use the 'yum' package installer instead of 'apt'. (Example: sudo yum install cifs-utils)

The following is also for use at the command line, via a terminal emulator.  That assumes you are comfortable and able to use a command line/terminal to enter commands.  If you are running a GUI desktop, open your file manager, and use the help function to learn how to mount/map a remote SMB/CIFS share, or use SFTP to do the same, etc...

Two methods are described below.  Both work, and both have their upside and downside.  Method 1 requires the use of the mount command, which requires root/sudo access.  Method 2 can be performed by the user, without root/sudo, once the packages have been installed.

Method 1: cifs-utils 

The first step in mounting your home directory folder on Linux is to install the cifs-utils package

 

Note: It is best practice to ensure your operating system and applications are up to date before attempting this. If you have a specific reason for not wanting to upgrade the operating system and applications, you can skip this prerequisite step. Otherwise, you can update the operating system and applications with the following commands:

sudo apt update

sudo apt upgrade

 

1.       Open a new Terminal window and enter the following command:

 

sudo apt install cifs-utils

 

2.       Follow the on-screen prompts to complete the installation

 

Mounting the Home Directory Folder

1.       Create a location that the share can be mounted to. In this example we used /mnt/share

sudo mkdir /mnt/share

* Note that to access the newly mounted share as a regular user, you will need to use chmod and possibly chgrp to set the proper permissions for the directory used as the mountpoint for the share.  (/mnt/share, in the above example). 

2.       Mount the share using your home directory path.  If you aren't sure what your home directory path is, please reach out to ECN via: https://engineering.purdue.edu/ECN/AboutUs/ContactUs  , or contact your local Academic IT Support group, if not supported by Engineering IT Support.

Note you will encounter two types of servers here at Purdue. The first type is a server which does not authenticate via Active Directory (AD), and the other are servers which do authenticate via Active Directory.

The general form of the mount command is shown below:

sudo mount -t cifs //server.ecn.purdue.edu/username /mnt/share --verbose -o user=USERNAME

The examples below use the username john123 as the username, and pier.ecn.purdue.edu for non-AD servers, and nas01.itap.purdue.edu for AD servers.  Substitute your own username and server where appropriate. 

* For non-AD servers, replace 'server' with your ECN home directory server name, and replace the 'username' portion with your Purdue career account username. 

(Example: sudo mount -t cifs //pier.ecn.purdue.edu/john123 /mnt/share --verbose -o user=john123).

* For servers using Active Directory, you will need to specify the domain via the workgroup option.

(Example: mount -t cifs //nas01.itap.purdue.edu/puhome  /mnt/share -o user=john123,domain=BOILERAD)  

 

Note: The above commands are all one line. There is a ‘space’ in between //server.ecn.purdue.edu/username and /mnt/share.  Also, when specifying the domain, it needs to be in ALL CAPS.

 3.       Enter your Purdue career account password when prompted. Your home directory folder should now be mounted. Now, change the directory to your mount location (i.e. /mnt/share) with the following command:

cd /mnt/share

 * Alternatively, you can view the mounted directory with your operating system's File Manager application.

  Method 2: gio/gvfs/fuse

This method assumes you have a Gnome-based/derived desktop installed.  If you do not, there are analogs for KDE, etc..., but are outside the scope of this document.  Essentially, what this does is use gio to access the underlying functionality the GUI Filemanager found in gnome desktops, to mount remote SMB/CIFS filesystems.

First, enter the gio command from the terminal prompt to make sure it is installed.  You should get a "Usage:" messaged, followed by several sub-commands.  If you get a "not found" error, then you may not have a Gnome-based GUI installed.

Once you have established gio is present, you can continue with the following:

First, you need to launch a dbus session with a new sub-shell:

dbus-run-session bash 

You will get your prompt right back, and it will appear to have done nothing, but this step must be completed for the underlying fuse/gvfs system to function.

Next, you will use gio to mount the remote filesystem.  The general form is:

gio mount smb://<server>/<share>

after you enter that command, you will be prompted for domain and password information.

Now, the downside of this method is that the mount occurs in a rather hard to use place in the filesystem, and there isn't much to be done about.  However, we can use a symlink to create a link to the actual mount, in a place that is easier to access, namely, your default home directory.  Again the general form is:

ln -s /run/user/<UID>/gvfs/smb-share\:server\=<server>\,share\=<share>/ ~/<mount point>

The UID is your user ID, which can be found with this command:

id -u

The server and share names should be self-explanatory.  Note that there is a space between the backslash and the '~'.  '~' is short=hand for your home directory.

<mount point> is a name you decide, such as remote-share.

Once that link is made, you can access the remote file system from a directory with the name you gave it in the <mount point> part of the command above.

One final note before an actual example:  Once the dbus session ends, the mount goes away.  However, the symlink, now pointing to nowhere, remains, and should be removed. 

Here is an example of Method 2.  The user name is rich, the server he is currently logged into is freighter, the remote server is named pier.ecn.purdue.edu, the share is the same as his username, "rich", and the mount point is "rich-remote":

-bash-4.2$ uname -a

Linux freighter.ecn.purdue.edu 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

-bash-4.2$ pwd

/home/freighter/a/rich

-bash-4.2$ dbus-run-session bash

bash-4.2$ gio mount smb://pier.ecn.purdue.edu/rich

Activating service name='org.gtk.vfs.Daemon'

Successfully activated service 'org.gtk.vfs.Daemon'

Activating service name='org.freedesktop.secrets'

Successfully activated service 'org.freedesktop.secrets'

Password required for share rich on pier.ecn.purdue.edu

User [rich]:

Domain [ECN]:

Password:

bash-4.2$ ln -s /run/user/17625/gvfs/smb-share\:server\=pier.ecn.purdue.edu\,share\=rich/ ~/rich-remote

bash-4.2$ cd rich-remote

bash-4.2$ ls

<all of rich's stuff on pier is listed>

If I ctrl-D or logout out of the dbus launched bash shell, the mount goes away, but the link (now bad) remains. Remove it:

rm –rf rich-remote

Should you desire to mount your space over on nas01.itap.purdue.edu, use "nas01.itap.purdue.edu/puhome" for the server/share name.

Automating the Mount

You are probably saying to yourself, I don't want to do this every time I login.

Here is how you can automated this process:

1) create a credentials file in your home directory.  We suggest making it a hidden (.<name>) file.  You should probably make the name something intuitive, such as .<server>-<share>.  For our pal Rich, used in the above example, he might choose use: .pier-rmf to for his home directory on pier.ecn.purdue.edu.  The format of the file is three separate lines, specifying username, workgroup/AD Name, and password.  Here is an example:

.pier-rich

rich

WORKGROUP

<password>

(note: there should be no spaces between these three lines, but there is a limitation in the editor used to create this document)

After creating the file, redirect the credentials file into the gio command, with the "<" redirection character, like this:

gio mount smb://pier.ecn.purdue.edu/rich <  /home/rich/.pier-rich

You would then create a link, as before, as shown in the example above.

Now that we have the method, we can automate this process.  Make sure you are you are your home directory, then edit the .bash_profile file.  Add the commands above to the file:

#mount the share

gio mount smb://pier.ecn.purdue.edu/rich <  /home/rich/.pier-rich

# create the link

ln -s /run/user/17625/gvfs/smb-share\:server\=pier.ecn.purdue.edu\,share\=rich/ ~/rich-remote

Then, logout, and test it.

Last Modified: Nov 15, 2023 1:05 pm US/Eastern
Created: Feb 25, 2022 2:11 pm US/Eastern by admin
JumpURL: None Found