Wise people learn when they can; fools learn when they must - Arthur Wellesley

Thursday, 27 July 2017

RHEL6–37–AUTOFS-2


RHEL6–37–AUTOFS-2


INDIRECT MAP:

This is the main reason because of “autofs” is too famous. Let’s assume there are several remote users in a network, jumping from this server to that server. They all need a space on each server to edit their files or do some data retrieval work. They can collect their data on each server and send it back to their home location, but this is not feasible. Also practically it is not possible to carry their home dir to each location while login to that server.

But what if they get their default home dir on each server as they logged in.

Let’s make it possible by “AUTOFS”

I have 4 machines, 1 is server and rest 3 are clients.

rhel6-server è Server

rhel6-test1 è Clint 1
pr01       è Clint 2
dr01        è Clint 3

AT SERVER:

[root@rhel6-server ~]# useradd -m -d /home/auto1 -s /bin/bash auto1
[root@rhel6-server ~]# passwd auto1
Changing password for user auto1.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

[root@rhel6-server ~]# vi /etc/exports
/home/auto1 *(rw)

[root@rhel6-server ~]# exportfs -av
exporting *:/home/auto1
exporting *:/autofs-test

[root@rhel6-server ~]# service autofs restart
Stopping automount:                                        [  OK  ]
Starting automount:                                        [  OK  ]
[root@rhel6-server ~]# service autofs reload
Reloading maps

AT CLIENT 1:

[root@rhel6-test1 /]# useradd auto1
[root@rhel6-test1 /]# passwd auto1
Changing password for user auto1.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

[root@rhel6-test1 /]# vi /etc/auto.master
/home /etc/auto.home

[root@rhel6-test1 /]# vi /etc/auto.home
auto1 192.168.234.146:/home/auto1

[root@rhel6-test1 /]# service autofs restart;service autofs reload
Stopping automount:                                        [  OK  ]
Starting automount:                                        [  OK  ]
Reloading maps

AT CLIENT 2:

[root@pr01 ~]# useradd auto1
[root@pr01 ~]# passwd auto1
Changing password for user auto1.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

[root@pr01 ~]# vi /etc/auto.master
/home /etc/auto.home

[root@pr01 ~]# vi /etc/auto.home
auto1 192.168.234.146:/home/auto1

[root@pr01 ~]# service autofs restart;service autofs reload
Stopping automount:                                        [  OK  ]
Starting automount:                                        [  OK  ]
Reloading maps

AT CLIENT 3:

[root@dr01 ~]# useradd auto1
[root@dr01 ~]# passwd auto1
Changing password for user auto1.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

[root@dr01 ~]# vi /etc/auto.master
/home /etc/auto.home

[root@dr01 ~]# vi /etc/auto.home
auto1 192.168.234.146:/home/auto1

[root@dr01 ~]# service autofs restart;service autofs reload
Stopping automount:                                        [  OK  ]
Starting automount:                                        [  OK  ]
Reloading maps

It will work….?  It should be…… because we did everything right.

Let’s check,

FROM SERVER:

[root@rhel6-server ~]# su - auto1
[auto1@rhel6-server ~]$ ssh 192.168.234.153
auto1@192.168.234.153's password:
Could not chdir to home directory /home/auto1: Permission denied
-bash: /home/auto1/.bash_profile: Permission denied
-bash-4.1$ hostname
dr01
-bash-4.1$ pwd
/

Check it at dr01,

[root@dr01 ~]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              13G  4.3G  7.7G  36% /
tmpfs                 497M   72K  497M   1% /dev/shm
/dev/sda1             485M   37M  423M   8% /boot
.host:/               108G  105G  3.3G  97% /mnt/hgfs
tmpfs                 4.0K     0  4.0K   0% /dev/vx
192.168.234.146:/home/auto1
                     1008M   34M  924M   4% /home/auto1

[root@dr01 ~]# su - auto1
su: warning: cannot change directory to /home/auto1: Permission denied
-bash: /home/auto1/.bash_profile: Permission denied
-bash-4.1$ pwd
/root

It means our config is not correct because getting errors,

What could be possible problem…….?
Config files… No, I think they are correct.

Then what…?

Permissions…?  Let’s check,

[root@rhel6-server ~]# ls -ld /home/auto1/
drwx------. 5 auto1 auto1 4096 Jul 27 17:44 /home/auto1/

It’s same everywhere. There is no issue with user “auto1” as well.

Then what…??????

Here we can see that, Owner has all the permissions. So according to “autofs” /home/auto1 is about to be mounted at each location, means user “auto1” would exists everywhere, and we have this already. Now what next…?

Let’s dig some more…

[root@rhel6-server ~]# grep auto1 /etc/passwd
auto1:x:502:502::/home/auto1:/bin/bash

[root@rhel6-test1 /]# grep auto1 /etc/passwd
auto1:x:503:503::/home/auto1:/bin/bash

[root@pr01 ~]# grep auto1 /etc/passwd
auto1:x:500:500::/home/auto1:/bin/bash

[root@dr01 ~]# grep auto1 /etc/passwd
auto1:x:501:501::/home/auto1:/bin/bash

Is this the problem…?

Let’s confirm…

Machines taken Server & pr01,

AT PR01:

[root@pr01 ~]# usermod -u 502 auto1
[root@pr01 ~]# groupmod -g 502 auto1
[root@pr01 ~]# service autofs restart;service autofs reload
Stopping automount:                                        [  OK  ]
Starting automount:                                        [  OK  ]
Reloading maps

FROM SERVER:

[auto1@rhel6-server ~]$ pwd
/home/auto1
[auto1@rhel6-server ~]$ ls -l
total 0
[auto1@rhel6-server ~]$ ssh 192.168.234.170
auto1@192.168.234.170's password:
Last login: Thu Jul 27 17:59:15 2017 from 192.168.234.146
[auto1@pr01 ~]$ pwd
/home/auto1
[auto1@pr01 ~]$ hostname
pr01
[auto1@pr01 ~]$ ls -l
total 0
[auto1@pr01 ~]$ touch f1 f2 f3
[auto1@pr01 ~]$ ls -l
total 0
-rw-rw-r-- 1 auto1 auto1 0 Jul 27 18:01 f1
-rw-rw-r-- 1 auto1 auto1 0 Jul 27 18:01 f2
-rw-rw-r-- 1 auto1 auto1 0 Jul 27 18:01 f3
[auto1@pr01 ~]$

AT PR01:

[root@pr01 ~]# w
 18:01:53 up  1:42,  3 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/1    192.168.234.1    22Apr17 96days  0.10s  0.10s -bash
root     pts/0    192.168.234.1    16:52    0.00s  0.16s  0.01s w
auto1    pts/2    192.168.234.146  18:01   26.00s  0.04s  0.04s –bash

[root@pr01 ~]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              13G  6.9G  5.0G  59% /
tmpfs                 497M     0  497M   0% /dev/shm
/dev/sda1             485M   37M  423M   8% /boot
.host:/               108G  105G  3.3G  97% /mnt/hgfs
tmpfs                 4.0K     0  4.0K   0% /dev/vx
192.168.234.146:/home/auto1
                     1008M   34M  924M   4% /home/auto1
[root@pr01 ~]#

[root@pr01 ~]# su - auto1
[auto1@pr01 ~]$ ls -l
total 0
-rw-rw-r-- 1 auto1 auto1 0 Jul 27 18:01 f1
-rw-rw-r-- 1 auto1 auto1 0 Jul 27 18:01 f2
-rw-rw-r-- 1 auto1 auto1 0 Jul 27 18:01 f3


AT SERVER:

[auto1@pr01 ~]$ exit
logout
Connection to 192.168.234.170 closed.
[auto1@rhel6-server ~]$ id
uid=502(auto1) gid=502(auto1) groups=502(auto1) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[auto1@rhel6-server ~]$ pwd
/home/auto1
[auto1@rhel6-server ~]$ ls -l
total 0
-rw-rw-r--. 1 auto1 auto1 0 Jul 27 18:01 f1
-rw-rw-r--. 1 auto1 auto1 0 Jul 27 18:01 f2
-rw-rw-r--. 1 auto1 auto1 0 Jul 27 18:01 f3

Now it supposed to be ok, the files created at “PR01” are still exists on local dir.

Let’s check it again with “DR01”, this time I will change only “uid”

Machines taken Server & dr01,

AT DR01:

Before Changes,

FROM SERVER:

[auto1@rhel6-server ~]$ ssh 192.168.234.153
The authenticity of host '192.168.234.153 (192.168.234.153)' can't be established.
RSA key fingerprint is cf:f0:1f:7f:60:33:63:1e:ba:50:be:5a:cb:81:ca:c7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.234.153' (RSA) to the list of known hosts.
auto1@192.168.234.153's password:
Could not chdir to home directory /home/auto1: Permission denied
-bash: /home/auto1/.bash_profile: Permission denied
-bash-4.1$ hostname
dr01
-bash-4.1$ pwd
/
-bash-4.1$ exit
logout
-bash: /home/auto1/.bash_logout: Permission denied
Connection to 192.168.234.153 closed.

AT DR01:

[root@dr01 ~]# usermod -u 502 auto1
[root@dr01 ~]# grep auto1 /etc/passwd
auto1:x:502:501::/home/auto1:/bin/bash
[root@dr01 ~]# !service
service autofs restart;service autofs reload
Stopping automount:                                        [  OK  ]
Starting automount:                                        [  OK  ]
Reloading maps

[root@dr01 ~]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              13G  4.3G  7.7G  36% /
tmpfs                 497M   72K  497M   1% /dev/shm
/dev/sda1             485M   37M  423M   8% /boot
.host:/               108G  105G  3.3G  97% /mnt/hgfs
tmpfs                 4.0K     0  4.0K   0% /dev/vx
[root@dr01 ~]#

FROM SERVER:

[auto1@rhel6-server ~]$ ssh 192.168.234.153
auto1@192.168.234.153's password:
Last login: Thu Jul 27 17:46:54 2017 from 192.168.234.146
[auto1@dr01 ~]$ hostname
dr01
[auto1@dr01 ~]$ pwd
/home/auto1
[auto1@dr01 ~]$ ls -l
total 0
-rw-rw-r-- 1 501 auto1 0 Jul 27 18:01 f1
-rw-rw-r-- 1 501 auto1 0 Jul 27 18:01 f2
-rw-rw-r-- 1 501 auto1 0 Jul 27 18:01 f3

[auto1@dr01 ~]$ touch dr01-1 dr01-2

[auto1@dr01 ~]$ ls -l
total 0
-rw-rw-r-- 1 501 nobody 0 Jul 27 18:10 dr01-1
-rw-rw-r-- 1 501 nobody 0 Jul 27 18:10 dr01-2
-rw-rw-r-- 1 501 auto1  0 Jul 27 18:01 f1
-rw-rw-r-- 1 501 auto1  0 Jul 27 18:01 f2
-rw-rw-r-- 1 501 auto1  0 Jul 27 18:01 f3
[auto1@dr01 ~]$

AT DR01:

[root@dr01 ~]# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              13G  4.3G  7.7G  36% /
tmpfs                 497M   72K  497M   1% /dev/shm
/dev/sda1             485M   37M  423M   8% /boot
.host:/               108G  105G  3.3G  97% /mnt/hgfs
tmpfs                 4.0K     0  4.0K   0% /dev/vx
192.168.234.146:/home/auto1
                     1008M   34M  924M   4% /home/auto1

I don’t know why it is nowhere mentioned to have same GID for mounting home dirs Via AUTOMOUNT. Or this might be particular case with me… LL

Anyways…

It means the UID should must same everywhere. Having same GID is not compulsory.
But better to use same UID & GID everywhere.

You might be annoyed; means if I knew this already then why did not mentioned it before…??

Dear, now you will never forget this silly mistake.

Now confirm it on last client as well,

Before changes,

[root@rhel6-server ~]# ssh auto1@192.168.234.200
auto1@192.168.234.200's password:
Last login: Thu Jul 27 17:24:20 2017 from rhel6-server
Could not chdir to home directory /home/auto1: Permission denied
-bash: /home/auto1/.bash_profile: Permission denied
-bash-4.1$ exit
logout
-bash: /home/auto1/.bash_logout: Permission denied
Connection to 192.168.234.200 closed.

[root@rhel6-test1 /]# usermod -u 502 auto1
usermod: UID '502' already exists

[root@rhel6-test1 /]# grep 502 /etc/passwd
user1:x:502:502::/home/user1:/bin/bash

Change the UID & GID of existing user “user1”

[root@rhel6-test1 /]# usermod -u 504 user1
[root@rhel6-test1 /]# groupmod -g 504 user1

Now Replace,

[root@rhel6-test1 /]# usermod -u 502 auto1
[root@rhel6-test1 /]# groupmod -g 502 auto1
[root@rhel6-test1 /]# !service
service autofs restart;service autofs reload
Stopping automount:                                        [  OK  ]
Starting automount:                                        [  OK  ]
Reloading maps

[auto1@rhel6-server ~]$ ssh 192.168.234.200
auto1@192.168.234.200's password:
Last login: Thu Jul 27 17:29:55 2017 from rhel6-server
[auto1@rhel6-test1 ~]$ hostname
rhel6-test1
[auto1@rhel6-test1 ~]$ pwd
/home/auto1
[auto1@rhel6-test1 ~]$ ls -l
total 0
-rw-rw-r--. 1 503 raman 0 Jul 27 18:10 dr01-1
-rw-rw-r--. 1 503 raman 0 Jul 27 18:10 dr01-2
-rw-rw-r--. 1 503   503 0 Jul 27 18:01 f1
-rw-rw-r--. 1 503   503 0 Jul 27 18:01 f2
-rw-rw-r--. 1 503   503 0 Jul 27 18:01 f3

Now all good…… JJJ

Enjoy……………………………………………………………………


<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({
          google_ad_client: "ca-pub-6906515461221883",
          enable_page_level_ads: true
     });
</script>

No comments:

Post a Comment