[SOLVED] automount /home of user to another directory when he logs in
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Normally the home folder of mike will be /home/mike; and so the following folder must exist on the NFS server with the appropriate permissions /var/nfs/mike.
You seem to only have the example and example2 folders.
Generally centralizing the users is part of a bigger organization with an LDAP or IPA infrastructure.
Are you using any?
Last edited by tshikose; 01-25-2017 at 06:33 PM.
Reason: typo with the CODE tag
I've corrected the typo of CODE tag, that you picked up and fixed correctly.
The & in * 192.168.122.1:/var/nfs/& means mount what_ever_folder is tried to be accessed in /home/what_ever_folder from the NFS //192.168.122.1:/var/nfs/what_ever_folder.
When a user logs in the system he is put in his home folder.
The user username home folder is defined at user creation. Generally, its default value is /home/username.
The home folder, being a home folder, is generally owned by the user only, permissions 700.
So /test/mike might not be a good home folder for user mike!
But
Code:
usermod -d /test/mike mike
or
Code:
usermod -m /home/mike -d /test/mike mike
do the trick with various effects.
You can go in the man pages of useradd, usermod and /etc/passwd.
The -bash-4.2$ you see is called the prompt.
I see noting wrong with it.
Why is it bothering you?
The answer to you question is yes.
But before giving any instruction, I need you to clearly explain what you really want to achieve.
If it is just for one user accessing an NFS folder, why not just mount that folder with that user ownership?
Bear in mind that normal user settings are global. Do you really want to affect other user home folders the way you are affecting mike's?
I want to automount using autofs the home directory of a user called bill.
[root@rh1 ~]# cd /home/ldap/
[root@rh1 ldap]# ls
bill
[root@rh1 ldap]# ls -l
total 0
drwxr-xr-x. 4 bill bill 64 Jan 29 12:31 bill
/home/ldap/bill is the home directory of bill.
NFS services is running on server
[root@rh1 ldap]# systemctl status nfs
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
Active: active (exited) since Sun 2017-01-29 13:26:06 CET; 14min ago
Process: 36899 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
Process: 36896 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)
Process: 36894 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
Process: 36915 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Process: 36914 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Main PID: 36915 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nfs-server.service
Jan 29 13:26:06 rh1.lab.local systemd[1]: Starting NFS server and services...
Jan 29 13:26:06 rh1.lab.local systemd[1]: Started NFS server and services.
[root@rh2 ~]# systemctl status autofs
● autofs.service - Automounts filesystems on demand
Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2017-01-29 13:34:09 CET; 9min ago
Process: 1223 ExecStart=/usr/sbin/automount $OPTIONS --pid-file /run/autofs.pid (code=exited, status=0/SUCCESS)
Main PID: 1226 (automount)
CGroup: /system.slice/autofs.service
└─1226 /usr/sbin/automount --pid-file /run/autofs.pid
Jan 29 13:34:09 rh2.lab.local systemd[1]: Starting Automounts filesystems on demand...
Jan 29 13:34:09 rh2.lab.local automount[1226]: setautomntent: lookup(sss): setautomntent: No such file or directory
Jan 29 13:34:09 rh2.lab.local automount[1226]: do_mount_autofs_indirect: failed to create ioctl fd for autofs path /.
Jan 29 13:34:09 rh2.lab.local automount[1226]: handle_mounts: mount of /. failed!
Jan 29 13:34:09 rh2.lab.local automount[1226]: master_do_mount: failed to startup mount
Jan 29 13:34:09 rh2.lab.local systemd[1]: Started Automounts filesystems on demand.
[root@rh2 ~]#
[root@rh1 ~]# ssh bill@192.168.122.37
bill@192.168.122.37's password:
Last login: Sun Jan 29 13:34:48 2017 from rh1.lab.local
Could not chdir to home directory /home/ldap/bill: No such file or directory
-bash-4.2$ pwd
/
-bash-4.2$ ls
bin dev home lib64 misc net proc run srv test usr
boot etc lib media mnt opt root sbin sys tmp var
-bash-4.2$ cd dirnet
-bash: cd: dirnet: No such file or directory
[root@rh2 ~]#
[root@rh2 ~]# su - bill
Last login: Sun Jan 29 16:03:06 CET 2017 on pts/1
-bash-4.2$
-bash-4.2$
-bash-4.2$ pwd
/home/ldap/bill
-bash-4.2$ cd dirnet
-bash-4.2$ ls
test
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.