LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-25-2017, 05:03 AM   #1
chtsalid
Member
 
Registered: Jan 2017
Posts: 67

Rep: Reputation: Disabled
automount /home of user to another directory when he logs in


Hi,

i am struggling by using autofs to mount the /home of user to another directory when he logs in.

e.g

when user mike logs in its /home directory to be mounted to /test

Many thanks!
 
Old 01-25-2017, 08:42 AM   #2
chtsalid
Member
 
Registered: Jan 2017
Posts: 67

Original Poster
Rep: Reputation: Disabled
Here is what I have done so far

on rh1(nfs server)

[root@rh1 ~]# cd /var/nfs/
[root@rh1 nfs]# ls
example example2

on rh3(nfs client using autofs)

cat /etc/auto.master
/home /etc/auto.home

cat /etc/auto.home
* 192.168.122.1:/var/nfs/

then I do su - mike

[root@rh3 ~]# su - mike
Last login: Tue Jan 24 18:46:13 CET 2017 on pts/0
-bash-4.2$ ls
example example2


! but then I go into bash, how can I change this?

Many thanks!
 
Old 01-25-2017, 09:40 AM   #3
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 478

Rep: Reputation: 91
Hi,

You should instead have
Code:
cat /etc/auto.home
* 192.168.122.1:/var/nfs/&
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
 
1 members found this post helpful.
Old 01-25-2017, 09:59 AM   #4
chtsalid
Member
 
Registered: Jan 2017
Posts: 67

Original Poster
Rep: Reputation: Disabled
thanks for your help! It is only for test perpuse, so no ldap or ipa.

I added the directory mike as you suggested! It is better now.

But I don't understand this &[/CODE]. What is the meaning?

Thanks!
 
Old 01-25-2017, 10:50 AM   #5
chtsalid
Member
 
Registered: Jan 2017
Posts: 67

Original Poster
Rep: Reputation: Disabled
I modified it as following,

* 192.168.122.1:/var/nfs/&

however I get the same -bash-4.2$

Any idea?

Many thanks!
 
Old 01-25-2017, 05:39 PM   #6
chtsalid
Member
 
Registered: Jan 2017
Posts: 67

Original Poster
Rep: Reputation: Disabled
Hi,

I found the reason for the appearence of bash by login. In /etc/auto.master I created

/home /etc/auto.home

after I deleted it, problem is fixed.

however could someone explain me how to:

automatically mount the home directory of a user e.g. mike, under /test when he logs on the system?

Many thanks!
 
Old 01-25-2017, 06:38 PM   #7
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 478

Rep: Reputation: 91
Hi,

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.
 
Old 01-25-2017, 06:51 PM   #8
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 478

Rep: Reputation: 91
Hi,

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?
 
Old 01-26-2017, 03:45 AM   #9
chtsalid
Member
 
Registered: Jan 2017
Posts: 67

Original Poster
Rep: Reputation: Disabled
thanks for you reply!

Is it possible to mount the 192.168.122.1:/var/nfs/& to another directory, instead of
mounting it to home directory of the user?

because currently it is mounted to home directory

-bash-4.2$ ls
mike1 mike2 mike3

Many thanks!
 
Old 01-26-2017, 04:53 AM   #10
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 478

Rep: Reputation: 91
Hi,

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?
 
Old 01-26-2017, 04:56 AM   #11
chtsalid
Member
 
Registered: Jan 2017
Posts: 67

Original Poster
Rep: Reputation: Disabled
Hi,

i am just doing this for testing purpose.
I found this in a book and I am trying to
complete it

Thank you!
 
Old 01-29-2017, 07:45 AM   #12
chtsalid
Member
 
Registered: Jan 2017
Posts: 67

Original Poster
Rep: Reputation: Disabled
Hi,

I need help in the following:

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.


On client now

[root@rh2 ~]# cat /etc/auto.master|grep ldap
/ /etc/auto.ldap

[root@rh2 ~]# cat /etc/auto.ldap|grep ldap
dirnet rh1.lab.local:/home/ldap/bill

[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@rh2 ~]# firewall-cmd --list-services
dhcpv6-client ftp http https ldap ldaps nfs ssh


[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


Any idea why it doesn't work?

Many thanks!
 
Old 01-29-2017, 02:03 PM   #13
chtsalid
Member
 
Registered: Jan 2017
Posts: 67

Original Poster
Rep: Reputation: Disabled
Ok, I did something

here is my autofs configuration

[root@rh2 ~]# cat /etc/auto.master|grep ldap
/home/ldap/bill /etc/auto.ldap

[root@rh2 ~]# cat /etc/auto.ldap|grep dirnet
dirnet -rw rh1.lab.local:/home/ldap/bill/

then we login using bill

[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

-bash-4.2$ pwd
/home/ldap/bill/dirnet
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
automount home directory for a specific user and1_hotsauce Linux - Newbie 3 05-16-2016 01:37 AM
[SOLVED] Automount other harddrives while encrypted home directory sadarax Linux - Security 5 11-06-2011 08:59 PM
Change Default Home Directory with LDAP and Automount greslore Linux - General 3 06-23-2009 04:32 PM
user's home directory on NFS server--what happens when user logs in from 2 computers? Mountain Linux - Networking 1 03-18-2009 04:35 PM
automount home directories with information from Active Directory (or NIS) alex r Linux - Software 5 08-30-2006 11:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration