Redhat: non-root user needs to copy files to a NFS share

5,334

The mount command can only be executed as root on most Linux systems, because it has a setuid of root set. There are 2 possible work arounds using the mount command, but they require that the root user (or somebody that can sudo to root) make some changes.

  1. Have them add an entry to /etc/fstab for the desired share. The noauto option is important.

    vi /etc/fstab
    <nfs ip or FQDN>:/      /mnt/       nfs rw,noauto,user,timeo=14,hard,intr 0 0
    

    Then have them run mount for the desired directory

    mount /mnt/
    
  2. Add the user to the suders file, specifying use of the mount command. Please note that this is less secure, because they can essentially mount anything on the file system. Run visudo and add a line like this:

    afhood    ALL=(ALL) /usr/bin/mount
    
  3. Perform some form of network based copying to the remote file system such as scp, rcp, ftp, sftp, etc. The specific command you would use is completely dependent on what the remote system allows and what you have installed on your system.

Share:
5,334

Related videos on Youtube

Sam
Author by

Sam

Updated on September 18, 2022

Comments

  • Sam
    Sam almost 2 years

    Typically non-root users cannot mount directories.

    Running Redhat Have 6GB tar.gz (/dir/somefile.tar.gz) Need to move to a NFS share on another box (//somebox/somefolder/)

    We have no other access.

    Any ideas?

    • vonbrand
      vonbrand over 11 years
      Need a lot more information... Do you have root on source, target, both? Do you have access to regular accounts on source, target, both? Can you use. e.g. scp(1), rsync(1), ...? Can you dismount the disk from the target, connect it to the source, and copy data that way? Are the sysadmins of target, source, or both, sensitive to bribery? Blackmail?
    • Bananguin
      Bananguin over 11 years
      and why don't you mount that nfs share as root? also, most desktop environments have some setuid services so that non root users can access network shares as tell. why don't you have one of those? Obviously, you can't copy a file to an unmounted remote nfs share. so you need to figure out a way to mount that share. why do the "normal" ways not work for you?
  • user1106106
    user1106106 over 11 years
    It should be mentioned that, to avoid errors while using sudo, one should use visudo, as it performs some syntax checking, as is explicitly stated in the manpage of sudoers(5).