設定autofs_setup

在Linux上的Terminal輸入指令,設定autofs以取得NAS伺服器端的文件

家目錄設置

>userdel -r user

>adduser user -M

先刪除原家目錄,再另創新的使用者並設置內容為空的家目錄資料夾

設置autofs

> cp auto.syno /etc/

> chmod +700 /etc/auto.syno

將synology提供的auto.syno文件複製至/etc/中

更改存取權限使擁有/etc/auto.syno的使用者可擁有讀、寫、執行的權限

啟用autofs

> mkdir -p /etc/mnt/nfs/opt/

> vim /etc/auto.master

"/home   program:/etc/auto.syno"

將路徑(雙引號裡的內容)加入auto.master的檔案中

auto.syno檔案

#!/bin/bash

# Copyright (c) 2000-2014 Synology Inc. All rights reserved.



################### NOTE ###################

#

# Adjust following settings to match your LDAP server.

#

# If using TLS or ldaps://, you have to append LDAP server's certificate to

# your client (in the file specified by tls_cacert in ldap.conf).

#

############################################ 


# LDAP server URI, must starts with "ldap://" or "ldaps://".

LDAP_URI="(請設置)"

# Search base of LDAP server.

BASE_DN="dc=ece,dc=cycu,dc=edu,dc=tw"

# "yes" or "no" means use TLS for LDAP connections or not.

USE_TLS="no"

# User-defined domain name (login suffix).

#DOMAIN_NAME="syno.com"

# NFS server, default use LDAP_URI.

NFS_SERVER="NAS的IP位置"

# NFS folder for home, default use /var/services/homes.

#NFS_FOLDER="/volume1/homes"

PWD="(NAS密碼"




# key=`echo $USER`

key=${1:-$(id -un)}


# test=${1:-$(id -un)}

# test1=${sv:-`whoami`}

# echo $test

# echo $test1

# echo $PWD


ToUpper() { ### <string>

echo "$1" | tr [:lower:] [:upper:]

}



ResolveDomainName() { ### <base_dn>

local token= domain=


for token in ${1//,/ }; do

domain="$domain.${token#*=}"

done

echo "`ToUpper ${domain:1}`"

}


if [ "$USE_TLS" = "yes" ]; then

opt="-Z $opt"

fi

if [ -z "$key" ]; then

exit 0

fi


if [ -z "$NFS_SERVER" ]; then

# Use pre-defined NFS server if any.

NFS_SERVER="${LDAP_URI#ldap*://}"

fi

if [ -n "$NFS_FOLDER" ]; then

# Use pre-defined NFS folder if any.

echo "-fstype=nfs $NFS_SERVER:${NFS_FOLDER// /\\ }/${key// /\\ }"

exit 0

fi



if [ -z "$LDAP_URI" -o -z "$BASE_DN" ]; then

>&2 echo "empty LDAP_URI or BASE_DN, please check your '$0'"

exit 1

fi


if [ -z "$DOMAIN_NAME" ]; then

domain="`ResolveDomainName $BASE_DN`"

else

# Use pre-defined domain name (login suffix) if any.

domain="`ToUpper $DOMAIN_NAME`"

fi

uid="`ldapsearch -H "ldap://192.168.1.113/" -b "dc=ece,dc=cycu,dc=edu,dc=tw" -D "uid=root,cn=users,dc=ece,dc=cycu,dc=edu,dc=tw" -w $PWD uid=$key | grep "uidNumber" | awk '{print $2}'`"

if [ -z "$uid" ]; then

>&2 echo "no uid found for user '$key'"

exit 1

fi

if ! [[ "$uid" =~ ^[0-9]+ ]]; then

>&2 echo "invalid uid '$uid'"

exit 1

fi

num=$(( $uid >> 14 ))


## uid="`ldapsearch -H "ldap://192.168.68.14/" -b "dc=ece,dc=cycu,dc=edu,dc=tw" -D "uid=root,cn=users,dc=ece,dc=cycu,dc=edu,dc=tw" -w $PWD uid=$key | grep "uidNumber" | awk '{print $2}'`"


## uid="`ldapsearch $opt "$LDAP_URI" -b "$BASE_DN" -D "uid=root,cn=users,dc=ece,dc=cycu,dc=edu,dc=tw" -w $PWD "uid=11178010" | grep 'uidNumber:' | awk '{print $2}'`"


echo "-rw,bg,soft,nolock,_netdev,nfsvers=3,udp,rsize=32768,wsize=32768 $NFS_SERVER:/volume1/homes/@LH-$domain/$num/${key// /\\ }-$uid"



# echo $uid