个人工具

“UbuntuHelp:NFSv4Howto”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/NFSv4Howto}}
 
{{From|https://help.ubuntu.com/community/NFSv4Howto}}
 
{{Languages|UbuntuHelp:NFSv4Howto}}
 
{{Languages|UbuntuHelp:NFSv4Howto}}
 
 
 
=== Installation ===
 
=== Installation ===
 
The required packages are different depending on if the system is a client or a server.  In this Howto, the server is the host that has the files you want to share and the client is the host that will be mounting the NFS share.
 
The required packages are different depending on if the system is a client or a server.  In this Howto, the server is the host that has the files you want to share and the client is the host that will be mounting the NFS share.
 
 
* NFSv4 client
 
* NFSv4 client
 
<pre><nowiki>
 
<pre><nowiki>
第12行: 第9行:
 
<pre><nowiki>
 
<pre><nowiki>
 
# apt-get install nfs-kernel-server </nowiki></pre>
 
# apt-get install nfs-kernel-server </nowiki></pre>
 
 
After you finish installing nfs-kernel-server, you might see failure to start nfs-kernel-server due to missing entries in /etc/exports. Remember to restart the service when you finish configuring.
 
After you finish installing nfs-kernel-server, you might see failure to start nfs-kernel-server due to missing entries in /etc/exports. Remember to restart the service when you finish configuring.
 
 
=== NFSv4 without Kerberos ===
 
=== NFSv4 without Kerberos ===
 
 
==== NFSv4 Server ====
 
==== NFSv4 Server ====
 
 
NFSv4 exports exist in a single ''pseudo filesystem'', where the
 
NFSv4 exports exist in a single ''pseudo filesystem'', where the
 
real directories are mounted with the <code><nowiki>--bind</nowiki></code> option. [http://www.citi.umich.edu/projects/nfsv4/linux/using-nfsv4.html Here] is some additional information
 
real directories are mounted with the <code><nowiki>--bind</nowiki></code> option. [http://www.citi.umich.edu/projects/nfsv4/linux/using-nfsv4.html Here] is some additional information
 
regarding this fact.
 
regarding this fact.
 
 
 
* Lets say we want to export our user homedirs in <code><nowiki>/home/users</nowiki></code>. First
 
* Lets say we want to export our user homedirs in <code><nowiki>/home/users</nowiki></code>. First
 
we create the export filesytem:
 
we create the export filesytem:
 
 
<pre><nowiki># mkdir /export
 
<pre><nowiki># mkdir /export
 
# mkdir /export/users </nowiki></pre>
 
# mkdir /export/users </nowiki></pre>
 
 
and mount the real users directory with:
 
and mount the real users directory with:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
# mount --bind /home/users /export/users</nowiki></pre>
 
# mount --bind /home/users /export/users</nowiki></pre>
 
 
To save us from retyping this after every reboot we add the following
 
To save us from retyping this after every reboot we add the following
 
line to <code><nowiki>/etc/fstab</nowiki></code>
 
line to <code><nowiki>/etc/fstab</nowiki></code>
 
<pre><nowiki>
 
<pre><nowiki>
 
/home/users    /export/users  none    bind  0  0</nowiki></pre>
 
/home/users    /export/users  none    bind  0  0</nowiki></pre>
 
 
* In <code><nowiki>/etc/default/nfs-kernel-server</nowiki></code> we set:
 
* In <code><nowiki>/etc/default/nfs-kernel-server</nowiki></code> we set:
 
<pre><nowiki>
 
<pre><nowiki>
 
NEED_SVCGSSD=no </nowiki></pre>
 
NEED_SVCGSSD=no </nowiki></pre>
 
because we do not activate NFSv4 security this time.
 
because we do not activate NFSv4 security this time.
 
 
* In <code><nowiki>/etc/default/nfs-common</nowiki></code> we set:
 
* In <code><nowiki>/etc/default/nfs-common</nowiki></code> we set:
 
<pre><nowiki>
 
<pre><nowiki>
 
NEED_IDMAPD=yes
 
NEED_IDMAPD=yes
 
NEED_GSSD=no </nowiki></pre>
 
NEED_GSSD=no </nowiki></pre>
 
 
* To export our directories to a local network 192.198.1.0/24
 
* To export our directories to a local network 192.198.1.0/24
 
we add the following two lines to <code><nowiki>/etc/exports</nowiki></code>
 
we add the following two lines to <code><nowiki>/etc/exports</nowiki></code>
第56行: 第40行:
 
/export/users 192.168.1.0/24(rw,nohide,insecure,no_subtree_check,async)
 
/export/users 192.168.1.0/24(rw,nohide,insecure,no_subtree_check,async)
 
</nowiki></pre>
 
</nowiki></pre>
 
 
* Restart the service
 
* Restart the service
 
<pre><nowiki>
 
<pre><nowiki>
 
# /etc/init.d/nfs-kernel-server restart</nowiki></pre>
 
# /etc/init.d/nfs-kernel-server restart</nowiki></pre>
 
 
==== NFSv4 Client ====
 
==== NFSv4 Client ====
 
 
* On the client we can mount the complete export tree with one command:
 
* On the client we can mount the complete export tree with one command:
 
<pre><nowiki>
 
<pre><nowiki>
 
# mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/ /mnt</nowiki></pre>
 
# mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/ /mnt</nowiki></pre>
 
 
* We can also mount an exported ''subtree'' with:
 
* We can also mount an exported ''subtree'' with:
 
<pre><nowiki>
 
<pre><nowiki>
 
# mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/users /home/users</nowiki></pre>
 
# mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/users /home/users</nowiki></pre>
 
 
* If you experience Problems like this:
 
* If you experience Problems like this:
 
<pre><nowiki>
 
<pre><nowiki>
第76行: 第55行:
 
All uids will be mapped to the nobody uid.
 
All uids will be mapped to the nobody uid.
 
mount: unknown filesystem type 'nfs4'</nowiki></pre>
 
mount: unknown filesystem type 'nfs4'</nowiki></pre>
 
 
then you need to set in <code><nowiki>/etc/default/nfs-common</nowiki></code>:
 
then you need to set in <code><nowiki>/etc/default/nfs-common</nowiki></code>:
 
<pre><nowiki>
 
<pre><nowiki>
 
NEED_IDMAPD=yes</nowiki></pre>
 
NEED_IDMAPD=yes</nowiki></pre>
 
 
and restart nfs-common
 
and restart nfs-common
 
<pre><nowiki>
 
<pre><nowiki>
 
# /etc/init.d/nfs-common restart</nowiki></pre>
 
# /etc/init.d/nfs-common restart</nowiki></pre>
 
The "unknown Filesystem" Error is ambiguous and will disappear as well.
 
The "unknown Filesystem" Error is ambiguous and will disappear as well.
 
 
=== NFSv4 with Kerberos ===
 
=== NFSv4 with Kerberos ===
 
 
You need a working Kerberos (MIT or Heimdal) KDC (Key Distribution Center)
 
You need a working Kerberos (MIT or Heimdal) KDC (Key Distribution Center)
 
before continuing. On the nfs-server and nfs-clients you must use MIT krb5
 
before continuing. On the nfs-server and nfs-clients you must use MIT krb5
 
for now.
 
for now.
 
 
When extracting the key to a keytab file and when configuring krb5
 
When extracting the key to a keytab file and when configuring krb5
 
in ''/etc/krb5.conf'' it is neccessary to specify
 
in ''/etc/krb5.conf'' it is neccessary to specify
 
''des-cbc-crc'' because only this type of encryption is supported by the
 
''des-cbc-crc'' because only this type of encryption is supported by the
 
kernel at the moment.
 
kernel at the moment.
 
 
* On the nfs-server and nfs-client you need at least the ''krb5-user''
 
* On the nfs-server and nfs-client you need at least the ''krb5-user''
 
and optinal ''libpam-krb5'' if you wish to authenticate against krb5.
 
and optinal ''libpam-krb5'' if you wish to authenticate against krb5.
 
<pre><nowiki># apt-get install krb5-user
 
<pre><nowiki># apt-get install krb5-user
 
# apt-get install libpam-krb5 </nowiki></pre>
 
# apt-get install libpam-krb5 </nowiki></pre>
 
 
* Specifiy ''des-cbc-crc'' in ''/etc/krb5.conf'' on nfs-servers and nfs-clients.
 
* Specifiy ''des-cbc-crc'' in ''/etc/krb5.conf'' on nfs-servers and nfs-clients.
 
<pre><nowiki>[libdefaults]
 
<pre><nowiki>[libdefaults]
 
default_tgs_enctypes = des-cbc-crc
 
default_tgs_enctypes = des-cbc-crc
 
default_tkt_enctypes = des-cbc-crc </nowiki></pre>
 
default_tkt_enctypes = des-cbc-crc </nowiki></pre>
 
 
* You need the gss kernel modules on nfs-servers and nfs-clients.
 
* You need the gss kernel modules on nfs-servers and nfs-clients.
 
<pre><nowiki>
 
<pre><nowiki>
第112行: 第83行:
 
Add ''rpcsec_gss_krb5'' to ''/etc/modules'' to have it loaded
 
Add ''rpcsec_gss_krb5'' to ''/etc/modules'' to have it loaded
 
automatically.
 
automatically.
 
 
==== Create and distribute credentials ====
 
==== Create and distribute credentials ====
 
 
NFSv4 needs machine credentials for the server and every client, which wants
 
NFSv4 needs machine credentials for the server and every client, which wants
 
to use the NFSv4 security features.
 
to use the NFSv4 security features.
 
 
Create the credentials for the nfs-server and all nfs-clients on the Kerberos KDC
 
Create the credentials for the nfs-server and all nfs-clients on the Kerberos KDC
 
and distribute the extraced keys with scp to the destination
 
and distribute the extraced keys with scp to the destination
 
 
===== Heimdal =====
 
===== Heimdal =====
 
<pre><nowiki># kinit kadmin/admin
 
<pre><nowiki># kinit kadmin/admin
 
 
# kadmin add -r nfs/nfs-server.domain
 
# kadmin add -r nfs/nfs-server.domain
 
# ktutil -k ~/keytab.nfs-server get -e des-cbc-crc nfs/nfs-server.domain
 
# ktutil -k ~/keytab.nfs-server get -e des-cbc-crc nfs/nfs-server.domain
 
# scp -p ~/keytab.nfs-server nfs-server:/etc/krb5.keytab
 
# scp -p ~/keytab.nfs-server nfs-server:/etc/krb5.keytab
 
 
# kadmin add -r nfs/nfs-client.domain
 
# kadmin add -r nfs/nfs-client.domain
 
# ktutil -k ~/keytab.nfs-client get -e des-cbc-crc nfs/nfs-client.domain
 
# ktutil -k ~/keytab.nfs-client get -e des-cbc-crc nfs/nfs-client.domain
 
# scp -p ~/keytab.nfs-client nfs-client:/etc/krb5.keytab
 
# scp -p ~/keytab.nfs-client nfs-client:/etc/krb5.keytab
 
 
# kdestroy </nowiki></pre>
 
# kdestroy </nowiki></pre>
 
 
===== MIT =====
 
===== MIT =====
 
<pre><nowiki># kinit admin/admin
 
<pre><nowiki># kinit admin/admin
 
 
# kadmin -q "addprinc -randkey nfs/nfs-server.domain"
 
# kadmin -q "addprinc -randkey nfs/nfs-server.domain"
 
# kadmin -q "ktadd -e des-cbc-crc:normal -k ~/keytab.nfs-server nfs/nfs-server.domain"
 
# kadmin -q "ktadd -e des-cbc-crc:normal -k ~/keytab.nfs-server nfs/nfs-server.domain"
 
# scp -p ~/keytab.nfs-server nfs-server.domain:/etc/krb5.keytab
 
# scp -p ~/keytab.nfs-server nfs-server.domain:/etc/krb5.keytab
 
 
# kadmin -q "addprinc -randkey nfs/nfs-client.domain"
 
# kadmin -q "addprinc -randkey nfs/nfs-client.domain"
 
# kadmin -q "ktadd -e des-cbc-crc:normal -k ~/keytab.nfs-client nfs/nfs-client.domain"
 
# kadmin -q "ktadd -e des-cbc-crc:normal -k ~/keytab.nfs-client nfs/nfs-client.domain"
 
# scp -p ~/keytab.nfs-client nfs-client.domain:/etc/krb5.keytab
 
# scp -p ~/keytab.nfs-client nfs-client.domain:/etc/krb5.keytab
 
 
# kdestroy </nowiki></pre>
 
# kdestroy </nowiki></pre>
 
 
 
==== NFSv4 Server ====
 
==== NFSv4 Server ====
 
 
* Check your machine credentials in ''/etc/krb5.keytab''
 
* Check your machine credentials in ''/etc/krb5.keytab''
 
<pre><nowiki># ktutil
 
<pre><nowiki># ktutil
第158行: 第115行:
 
1    2 nfs/nfs-server.domain@DOMAIN
 
1    2 nfs/nfs-server.domain@DOMAIN
 
</nowiki></pre>
 
</nowiki></pre>
 
 
* In <code><nowiki>/etc/default/nfs-kernel-server</nowiki></code> we set:
 
* In <code><nowiki>/etc/default/nfs-kernel-server</nowiki></code> we set:
 
<pre><nowiki>
 
<pre><nowiki>
 
NEED_SVCGSSD=yes </nowiki></pre>
 
NEED_SVCGSSD=yes </nowiki></pre>
 
 
* In <code><nowiki>/etc/default/nfs-common</nowiki></code> we set:
 
* In <code><nowiki>/etc/default/nfs-common</nowiki></code> we set:
 
<pre><nowiki>
 
<pre><nowiki>
 
NEED_IDMAPD=yes </nowiki></pre>
 
NEED_IDMAPD=yes </nowiki></pre>
 
 
* To export our directories from the example above to a
 
* To export our directories from the example above to a
 
local network 192.198.1.0/24 and addt
 
local network 192.198.1.0/24 and addt
第179行: 第133行:
 
/export/users gss/krb5(rw,nohide,insecure, \
 
/export/users gss/krb5(rw,nohide,insecure, \
 
no_subtree_check,async,anonuid=65534,anongid=65534) </nowiki></pre>
 
no_subtree_check,async,anonuid=65534,anongid=65534) </nowiki></pre>
 
 
Please note that you can specify allowed hosts only in
 
Please note that you can specify allowed hosts only in
 
the ''any authentication'' flavor. gss/krb5 flavours
 
the ''any authentication'' flavor. gss/krb5 flavours
 
are accessible from anywhere, if do not use an additional
 
are accessible from anywhere, if do not use an additional
 
firewall rules.
 
firewall rules.
 
 
To export only with secure authentication flavors do
 
To export only with secure authentication flavors do
 
not include a ''host(...)'' line in ''/etc/exports''
 
not include a ''host(...)'' line in ''/etc/exports''
 
 
To display your exports enter:
 
To display your exports enter:
 
<pre><nowiki>
 
<pre><nowiki>
 
# exportfs -v </nowiki></pre>
 
# exportfs -v </nowiki></pre>
 
 
 
==== NFSv4 Client ====
 
==== NFSv4 Client ====
 
 
* Check your machine credentials in ''/etc/krb5.keytab''
 
* Check your machine credentials in ''/etc/krb5.keytab''
 
<pre><nowiki># ktutil
 
<pre><nowiki># ktutil
第203行: 第151行:
 
1    2 nfs/nfs-client.domain@DOMAIN
 
1    2 nfs/nfs-client.domain@DOMAIN
 
</nowiki></pre>
 
</nowiki></pre>
 
 
* In <code><nowiki>/etc/default/nfs-common</nowiki></code> we set:
 
* In <code><nowiki>/etc/default/nfs-common</nowiki></code> we set:
 
<pre><nowiki>
 
<pre><nowiki>
 
NEED_IDMAPD=yes
 
NEED_IDMAPD=yes
 
NEED_GSSD=yes </nowiki></pre>
 
NEED_GSSD=yes </nowiki></pre>
 
 
* We can ''secure'' mount the complete export tree with:
 
* We can ''secure'' mount the complete export tree with:
 
<pre><nowiki>
 
<pre><nowiki>
 
# mount -t nfs4 -o sec=krb5,proto=tcp,port=2049 nfs-server:/ /mnt</nowiki></pre>
 
# mount -t nfs4 -o sec=krb5,proto=tcp,port=2049 nfs-server:/ /mnt</nowiki></pre>
 
 
* We can also ''secure'' mount an exported ''subtree'' with:
 
* We can also ''secure'' mount an exported ''subtree'' with:
 
<pre><nowiki>
 
<pre><nowiki>
 
# mount -t nfs4 -o sec=krb5,proto=tcp,port=2049 nfs-server:/users /home/users</nowiki></pre>
 
# mount -t nfs4 -o sec=krb5,proto=tcp,port=2049 nfs-server:/users /home/users</nowiki></pre>
 
 
=== Troubleshooting ===
 
=== Troubleshooting ===
 
 
First, take care of proper logging - by default almost nothing is logged.
 
First, take care of proper logging - by default almost nothing is logged.
 
 
e.g. to enable 3rd level verbose logging for rpc.gssd, append the following to {{/etc/default/nfs-common}}:
 
e.g. to enable 3rd level verbose logging for rpc.gssd, append the following to {{/etc/default/nfs-common}}:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
RPCGSSDOPTS=-vvv
 
RPCGSSDOPTS=-vvv
 
</nowiki></pre>
 
</nowiki></pre>
 
 
After restarting nfs-common (<code><nowiki>/etc/init.d/nfs-common restart</nowiki></code>) check that the daemon has received new arguments:  
 
After restarting nfs-common (<code><nowiki>/etc/init.d/nfs-common restart</nowiki></code>) check that the daemon has received new arguments:  
 
 
<pre><nowiki>
 
<pre><nowiki>
 
ps xuwa | grep grep rpc.gssd
 
ps xuwa | grep grep rpc.gssd
 
root      9857  0.0  0.4  2496  1220 ?        Ss  02:17  0:00 /usr/sbin/rpc.gssd -vvv
 
root      9857  0.0  0.4  2496  1220 ?        Ss  02:17  0:00 /usr/sbin/rpc.gssd -vvv
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Then look for its log output in damon.log:
 
Then look for its log output in damon.log:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
tail -f /var/log/daemon.log
 
tail -f /var/log/daemon.log
 
</nowiki></pre>
 
</nowiki></pre>
 
 
For the server, you can e.g. raise rpc.svcgssd log level in <code><nowiki>/etc/default/nfs-kernel-server</nowiki></code>:
 
For the server, you can e.g. raise rpc.svcgssd log level in <code><nowiki>/etc/default/nfs-kernel-server</nowiki></code>:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
RPCSVCGSSDOPTS=-vvv
 
RPCSVCGSSDOPTS=-vvv
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Browse the <code><nowiki>/etc/init.d/nfs-*</nowiki></code> init scripts to see other variables that you can set in <code><nowiki>/etc/defaults</nowiki></code>.
 
Browse the <code><nowiki>/etc/init.d/nfs-*</nowiki></code> init scripts to see other variables that you can set in <code><nowiki>/etc/defaults</nowiki></code>.
 
 
If using Kerberos, enable logging in <code><nowiki>/etc/krb5.conf</nowiki></code>:
 
If using Kerberos, enable logging in <code><nowiki>/etc/krb5.conf</nowiki></code>:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
[logging]
 
[logging]
第256行: 第188行:
 
default = SYSLOG:INFO:DAEMON
 
default = SYSLOG:INFO:DAEMON
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
 
=== Links ===
 
=== Links ===
 
 
* [http://www.citi.umich.edu/projects/nfsv4/linux Umich CITI intructions]
 
* [http://www.citi.umich.edu/projects/nfsv4/linux Umich CITI intructions]
 
* [http://www.vanemery.com/Linux/NFSv4/NFSv4-no-rpcsec.html Learning NFSv4 with Fedora Core 2]
 
* [http://www.vanemery.com/Linux/NFSv4/NFSv4-no-rpcsec.html Learning NFSv4 with Fedora Core 2]
 
 
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
 
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月30日 (五) 20:49的版本

Installation

The required packages are different depending on if the system is a client or a server. In this Howto, the server is the host that has the files you want to share and the client is the host that will be mounting the NFS share.

  • NFSv4 client
# apt-get install nfs-common 
  • NFSv4 server
# apt-get install nfs-kernel-server 

After you finish installing nfs-kernel-server, you might see failure to start nfs-kernel-server due to missing entries in /etc/exports. Remember to restart the service when you finish configuring.

NFSv4 without Kerberos

NFSv4 Server

NFSv4 exports exist in a single pseudo filesystem, where the real directories are mounted with the --bind option. Here is some additional information regarding this fact.

  • Lets say we want to export our user homedirs in /home/users. First

we create the export filesytem:

# mkdir /export
# mkdir /export/users 

and mount the real users directory with:

# mount --bind /home/users /export/users

To save us from retyping this after every reboot we add the following line to /etc/fstab

/home/users    /export/users   none    bind  0  0
  • In /etc/default/nfs-kernel-server we set:
NEED_SVCGSSD=no 

because we do not activate NFSv4 security this time.

  • In /etc/default/nfs-common we set:
NEED_IDMAPD=yes
NEED_GSSD=no 
  • To export our directories to a local network 192.198.1.0/24

we add the following two lines to /etc/exports

/export       192.168.1.0/24(ro,fsid=0,insecure,no_subtree_check,async)
/export/users 192.168.1.0/24(rw,nohide,insecure,no_subtree_check,async)
  • Restart the service
# /etc/init.d/nfs-kernel-server restart

NFSv4 Client

  • On the client we can mount the complete export tree with one command:
# mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/ /mnt
  • We can also mount an exported subtree with:
# mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/users /home/users
  • If you experience Problems like this:
Warning: rpc.idmapd appears not to be running.
All uids will be mapped to the nobody uid.
mount: unknown filesystem type 'nfs4'

then you need to set in /etc/default/nfs-common:

NEED_IDMAPD=yes

and restart nfs-common

# /etc/init.d/nfs-common restart

The "unknown Filesystem" Error is ambiguous and will disappear as well.

NFSv4 with Kerberos

You need a working Kerberos (MIT or Heimdal) KDC (Key Distribution Center) before continuing. On the nfs-server and nfs-clients you must use MIT krb5 for now. When extracting the key to a keytab file and when configuring krb5 in /etc/krb5.conf it is neccessary to specify des-cbc-crc because only this type of encryption is supported by the kernel at the moment.

  • On the nfs-server and nfs-client you need at least the krb5-user

and optinal libpam-krb5 if you wish to authenticate against krb5.

# apt-get install krb5-user
# apt-get install libpam-krb5 
  • Specifiy des-cbc-crc in /etc/krb5.conf on nfs-servers and nfs-clients.
[libdefaults]
default_tgs_enctypes = des-cbc-crc
default_tkt_enctypes = des-cbc-crc 
  • You need the gss kernel modules on nfs-servers and nfs-clients.
# modprobe rpcsec_gss_krb5 

Add rpcsec_gss_krb5 to /etc/modules to have it loaded automatically.

Create and distribute credentials

NFSv4 needs machine credentials for the server and every client, which wants to use the NFSv4 security features. Create the credentials for the nfs-server and all nfs-clients on the Kerberos KDC and distribute the extraced keys with scp to the destination

Heimdal
# kinit kadmin/admin
# kadmin add -r nfs/nfs-server.domain
# ktutil -k ~/keytab.nfs-server get -e des-cbc-crc nfs/nfs-server.domain
# scp -p ~/keytab.nfs-server nfs-server:/etc/krb5.keytab
# kadmin add -r nfs/nfs-client.domain
# ktutil -k ~/keytab.nfs-client get -e des-cbc-crc nfs/nfs-client.domain
# scp -p ~/keytab.nfs-client nfs-client:/etc/krb5.keytab
# kdestroy 
MIT
# kinit admin/admin
# kadmin -q "addprinc -randkey nfs/nfs-server.domain"
# kadmin -q "ktadd -e des-cbc-crc:normal -k ~/keytab.nfs-server nfs/nfs-server.domain"
# scp -p ~/keytab.nfs-server nfs-server.domain:/etc/krb5.keytab
# kadmin -q "addprinc -randkey nfs/nfs-client.domain"
# kadmin -q "ktadd -e des-cbc-crc:normal -k ~/keytab.nfs-client nfs/nfs-client.domain"
# scp -p ~/keytab.nfs-client nfs-client.domain:/etc/krb5.keytab
# kdestroy 

NFSv4 Server

  • Check your machine credentials in /etc/krb5.keytab
# ktutil
ktutil:  rkt /etc/krb5.keytab 
ktutil:  list
slot KVNO Principal
---- ---- ---------------------------------------------------------------------
1    2 nfs/nfs-server.domain@DOMAIN
  • In /etc/default/nfs-kernel-server we set:
NEED_SVCGSSD=yes 
  • In /etc/default/nfs-common we set:
NEED_IDMAPD=yes 
  • To export our directories from the example above to a

local network 192.198.1.0/24 and addt we add the following two lines to /etc/exports

/export       192.168.1.0/24(ro,fsid=0,insecure, \
no_subtree_check,async,anonuid=65534,anongid=65534)
/export       gss/krb5(ro,fsid=0,insecure, \
no_subtree_check,async,anonuid=65534,anongid=65534)
/export/users 192.168.1.0/24(rw,nohide,insecure, \
no_subtree_check,async,anonuid=65534,anongid=65534)
/export/users gss/krb5(rw,nohide,insecure, \
no_subtree_check,async,anonuid=65534,anongid=65534) 

Please note that you can specify allowed hosts only in the any authentication flavor. gss/krb5 flavours are accessible from anywhere, if do not use an additional firewall rules. To export only with secure authentication flavors do not include a host(...) line in /etc/exports To display your exports enter:

# exportfs -v 

NFSv4 Client

  • Check your machine credentials in /etc/krb5.keytab
# ktutil
ktutil:  rkt /etc/krb5.keytab 
ktutil:  list
slot KVNO Principal
---- ---- ---------------------------------------------------------------------
1    2 nfs/nfs-client.domain@DOMAIN
  • In /etc/default/nfs-common we set:
NEED_IDMAPD=yes
NEED_GSSD=yes 
  • We can secure mount the complete export tree with:
# mount -t nfs4 -o sec=krb5,proto=tcp,port=2049 nfs-server:/ /mnt
  • We can also secure mount an exported subtree with:
# mount -t nfs4 -o sec=krb5,proto=tcp,port=2049 nfs-server:/users /home/users

Troubleshooting

First, take care of proper logging - by default almost nothing is logged. e.g. to enable 3rd level verbose logging for rpc.gssd, append the following to 模板:/etc/default/nfs-common:

RPCGSSDOPTS=-vvv

After restarting nfs-common (/etc/init.d/nfs-common restart) check that the daemon has received new arguments:

ps xuwa | grep grep rpc.gssd
root      9857  0.0  0.4   2496  1220 ?        Ss   02:17   0:00 /usr/sbin/rpc.gssd -vvv

Then look for its log output in damon.log:

tail -f /var/log/daemon.log

For the server, you can e.g. raise rpc.svcgssd log level in /etc/default/nfs-kernel-server:

RPCSVCGSSDOPTS=-vvv

Browse the /etc/init.d/nfs-* init scripts to see other variables that you can set in /etc/defaults. If using Kerberos, enable logging in /etc/krb5.conf:

[logging]
kdc = SYSLOG:INFO:DAEMON
admin_server = SYSLOG:INFO:DAEMON
default = SYSLOG:INFO:DAEMON

Links