Child pages
  • Using Box under Linux
Skip to end of metadata
Go to start of metadata

Before you will be able to use SFTP, WebDAV, or DAVFS with your IU Box account, you must first create an external password. See the KB page Creating and using an external password for Enterprise Box for instructions.

Many people are using Box.com Cloud Storage and taking advantage of the benefits of the IU Box Service. Even though there is no Box Sync for the Linux platform, it can still be used effectively via HTTPS and DAV.

HTTPS Access

You can access your IU Box account using the link for the IU Box Service. Using this url provides the convenience and security of CAS and single sign-on with your IU Network ID. While the web interface may not be ideal for all applications, it does give you access to your account as well as the ability to preview, upload, and download files.  There is no Box Edit available for Linux so that functionality is not available.  However, the Box for Office Online features are supported which provides an extremely convenient way to create, edit, and share Word, Excel, and Powerpoint files directly from a browser.

SFTP (lftp)

Please note that you should never use the standard FTP protocol with ftp.box.com since your login credentials will be transferred across the network in clear text.  IU Box will fail if you attempt an unencrypted FTP connections but even a failed FTP login attempt will send your credentials in cleartext so you want to be sure never to use the FTP protocol.

The lftp command is a powerful file transfer client that can be used with Box.  Box supports the secure FTPS protocol and you can use this with lftp for secure file transfer and mirroring.  Here is an example of how to connect using FTPS.  The lftp command is smart enough to auto-negotiate to use FTPS but this example forces the issue to make absolutely sure unencrypted FTP is never attempted.

$ lftp
lftp :~> set ftps:initial-prot ""
lftp :~> set ftp:ssl-force true
lftp :~> set ftp:ssl-protect-data true
lftp :~> open ftps://ftp.box.com:990
lftp ftp.box.com:~> user username@indiana.edu
Password: 
lftp username@indiana.edu@ftp.box.com:~> ls
...

Once you are connected, you can use normal FTP commands like ls, get, put, etc.

One interesting application of lsftp with Box is using it to mirror a local directory similar to what Box Sync does, albeit in a more manual way.  The best way to explain this is by example so here is a sample script that mirrors a local /u/username/MyProject directory to Box into a folder of the same name (MyProject):

#!/bin/bash
lftp -c 'open -e "set ftps:initial-prot ""; \
   set ftp:ssl-force true; \
   set ftp:ssl-protect-data true; \
   open ftps://ftp.box.com:990; \
   user username@indiana.edu; \
   mirror --reverse --delete --no-perms --verbose "/u/username/MyProject" MyProject;" '

When you run this script, it will prompt for a password and then mirror your local directory to Box.  Each time you run it, it will re-sync any changes on the local filesystem with the copy on Box.  The --verbose option causes lftp to tell you exactly what it is doing.  If you are doing this via crontab, you probably want to remove that and you will also need to pass along the password in the script so do that with caution.

Note that when using this method, you may have it fail with this message:

Login failed: 530 Box: CAPTCHA is required. Please log into www.box.com in a web browser, and then try again.

If that happens, just go to https://box.iu.edu/ and log in using your IU SSO credentials.

WebDAV Access (Cadaver)

Cadaver is a command-line WebDAV client that allows access to your Box account. You can use the cadaver command as follows:

cadaver https://dav.box.com/dav

When prompted, just enter your username (like username@indiana.edu) and external password (see note at the top of this page).

Once you get logged in, you can use a number of cadaver commands like ls, get, and put. Type help to get a list of commands and help command to get help for an individual command.

While we never recommend putting cleartext passwords in files, do note that it is possible to set usernames and passwords for cadaver via the ~/.netrc configuration file login and password tokens. This would allow unattended upload and download of files and could be used for things like scripting and cron jobs. See the description of the .netrc file in the cadaver man page for details.

WebDAV Access (Nautilus)

This does not work reliably on Red Hat Enterprise Linux 6 so you should upgrade to Red Hat Enterprise Linux 7 before using this option.

You can use the nautilus file manager in Gnome to access your Box space. There are a number of ways to do this but on the SoIC Red Hat Linux 7 systems you can do the following:

  1. From the Places menu, select any option to bring up Nautilus
  2. Select Connect to Server
  3. For  Server Address enter: davs://username%40indiana.edu@dav.box.com/dav
    Replace username with your IU username.  The '%40' is the character encoding for '@' and you must leave that there exactly as shown.  You may need to use iu.edu (or some other IU domain) instead of indiana.edu depending on the email address you used when you created your external box account.
  4. Click Connect and, when prompted, enter your external password for Enterprise Box (see note at the top of this page)

This should bring up a File Browser window showing you the files you have in your Box space.

Mounting Box (davfs2)

This does not work reliably on Red Hat Enterprise Linux 6 so you should upgrade to Red Hat Enterprise Linux 7 before using this option.

If you want to mount your Box space onto a directory so you have transparent filesystem access, you can do this using davfs2.  The steps are detailed below. The first section lists configuration steps requiring root/sudo privileges. You will need to contact us if you need this done on an SoIC unified linux system.

DAVFS Setup Steps Requiring Root Access

  1. Install davfs2 - The davfs2 package will need to be installed. These instructions assume you have version 1.4.7 or newer.   On Red Hat Enterprise Linux 7, the davfs2 rpm is available from the EPEL repository.
  2. You need to create a directory you will use as the mount point. On the unified linux systems your home directory is mounted from a central file server so we recommend that you do not use a directory within your normal home directory. Contact us and we can create a directory /home/username/box on the local system to use for this purpose.
  3. You need to be added to the davfs2 group.
  4. Add the "use_locks 0" configuration option to /etc/davfs2/davfs2.conf.
  5. You then need to add an entry to /etc/fstab that looks like:

    https://dav.box.com/dav/ /home/username/box  davfs  rw,user,noauto 0 0
    

DAVFS Setup Steps To Be Done By The User

  1. Copy the /etc/davfs2 directory to .davfs2 in your home directory.

    $ cp -r /etc/davfs2 ~/.davfs2
    

    Note that you will get a permission denied error on the secrets file but that can be ignored.

  2. Create a file (using your favorite editor) named secrets in the .davfs2 directory that contains a single line using one of the following formats:

    https://dav.box.com/dav box_username
    
      --or--
    
    https://dav.box.com/dav box_username  "box_password"
    
    where:
    
       box_username = Your box username, such as username@indiana.edu for the IU Box service
       box_password = Your box password.  Note that this will be the external password (see note at the top of this page) and not your IU Network ID.
    

    You are strongly advised to use the first format that omits the password. When using this format, you will be prompted for your password when you run the mount command. If you need unattended access without prompting for a password you can include the password. If you do include your password, you MUST make sure this file is not readable by others which you can do with:

    $ chmod 600 ~/.davfs2/secret
    

DAVFS Mounting and Unmounting

Once all of this setup is done, you can then mount and unmount your Box filesystem as follows and no root/sudo access is needed:

To Mount:   mount /home/username/box
  ** You may see an error about writing to mtab which you can ignore

To Unmount: fusermount -u /home/username/box

The argument to the mount and fusermount commands must match exactly the second entry on the line you added to /etc/fstab above.

You are strongly advised to unmount the filesystem when not in use.