diff --git a/lustre/tests/llmount.sh b/lustre/tests/llmount.sh
index a8901ba1dde7dab20f820e3c8256050a11ad8962..253932f6c18ae56a0ad71c8c7b82fb628dd8bd80 100755
--- a/lustre/tests/llmount.sh
+++ b/lustre/tests/llmount.sh
@@ -13,6 +13,8 @@ mkconfig=$(dirname $0)/$NAME.sh
 
 . krb5_env.sh
 start_krb5_kdc || exit 1
+start_lsvcgssd || exit 2
+start_lgssd || exit 3
 
 if [ "$PORTALS" ]; then
     portals_opt="--portals=$PORTALS"
@@ -25,23 +27,17 @@ fi
 if [ "$LDAPURL" ]; then
     conf_opt="--ldapurl $LDAPURL --config $NAME"
 else
-    sh $mkconfig $config || exit 2
+    sh $mkconfig $config || exit 4
     conf_opt="$config"
 fi    
 
 [ "$NODE" ] && node_opt="--node $NODE"
 [ "$DEBUG" ] && debug_opt="--ptldebug=$DEBUG"
 
-# We'd better start lsvcgssd after gss modules loaded.
-# remove this if we don't depend on lsvcgssd in the future
-${LCONF} --nosetup --sec $SECURITY $portals_opt $node_opt $@ $conf_opt || exit 3
-start_lsvcgssd || exit 4
-start_lgssd || exit 5
-
 ${LCONF} $NOMOD --sec $SECURITY $portals_opt $lustre_opt $node_opt \
-         ${REFORMAT:---reformat} $@ $conf_opt  || exit 6
+         ${REFORMAT:---reformat} $@ $conf_opt  || exit 5
 
 if [ "$MOUNT2" ]; then
-       $LLMOUNT -v -o sec=$SECURITY `hostname`:/mds1/client $MOUNT2 || exit 7
+       $LLMOUNT -v -o sec=$SECURITY `hostname`:/mds1/client $MOUNT2 || exit 6
 fi
 
diff --git a/lustre/tests/llrmount.sh b/lustre/tests/llrmount.sh
index 3de7fcf14a0fa3552362e56b99381c03d72cc4bf..0cc28531049a7d0dc1c0cb03145d3ee04d599390 100755
--- a/lustre/tests/llrmount.sh
+++ b/lustre/tests/llrmount.sh
@@ -13,6 +13,8 @@ mkconfig=$NAME.sh
 . krb5_env.sh
 
 start_krb5_kdc || exit 1
+start_lsvcgssd || exit 2
+start_lgssd || exit 3
 
 if [ "$PORTALS" ]; then
   portals_opt="--portals=$PORTALS"
@@ -26,23 +28,17 @@ if [ "$LDAPURL" ]; then
     conf_opt="--ldapurl $LDAPURL --config $NAME"
 else
     if [ ! -f $config -o $mkconfig -nt $config ]; then
-	sh $mkconfig $config || exit 2
+	sh $mkconfig $config || exit 4
     fi
     conf_opt="$config"
 fi    
 
 [ "$NODE" ] && node_opt="--node $NODE"
 
-# We'd better start lsvcgssd after gss modules loaded.
-# remove this if we don't depend on lsvcgssd in the future
-${LCONF} --nosetup --sec $SECURITY $portals_opt $node_opt $@ $conf_opt || exit 3
-start_lsvcgssd || exit 4
-start_lgssd || exit 5
-
 ${LCONF} $NOMOD --sec $SECURITY $portals_opt $lustre_opt $node_opt \
-         $@ $conf_opt  || exit 6
+         $@ $conf_opt  || exit 5
 
 if [ "$MOUNT2" ]; then
-       $LLMOUNT -v -o sec=$SECURITY `hostname`:/mds1/client $MOUNT2 || exit 7
+       $LLMOUNT -v -o sec=$SECURITY `hostname`:/mds1/client $MOUNT2 || exit 6
 fi
 
diff --git a/lustre/tests/recovery-small.sh b/lustre/tests/recovery-small.sh
index 2f84c01c517dfd8d5b9c4df2fd7f0c6f3bbfa314..ac1a8115757e4a317a322592dd47298df54453b4 100755
--- a/lustre/tests/recovery-small.sh
+++ b/lustre/tests/recovery-small.sh
@@ -51,10 +51,10 @@ gen_config() {
 setup() {
     gen_config
     start_krb5_kdc || exit 1
-    start ost --reformat $OSTLCONFARGS 
-    start ost2 --reformat $OSTLCONFARGS 
     start_lsvcgssd || exit 2
     start_lgssd || exit 3
+    start ost --reformat $OSTLCONFARGS 
+    start ost2 --reformat $OSTLCONFARGS 
     [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
     for mds in `mds_list`; do
 	start $mds --reformat $MDSLCONFARGS
@@ -67,10 +67,10 @@ cleanup() {
     for mds in `mds_list`; do
 	stop $mds ${FORCE} $MDSLCONFARGS
     done
-    stop_lgssd
-    stop_lsvcgssd
     stop ost2 ${FORCE} --dump cleanup.log
     stop ost ${FORCE} --dump cleanup.log
+    stop_lgssd
+    stop_lsvcgssd
 }
 
 if [ ! -z "$EVAL" ]; then
diff --git a/lustre/tests/replay-dual.sh b/lustre/tests/replay-dual.sh
index bd5a748006613cfb000a0253499332ddcb4e6c3e..a09ef1bf47da642667a9662e8cef41458c9394b9 100755
--- a/lustre/tests/replay-dual.sh
+++ b/lustre/tests/replay-dual.sh
@@ -63,10 +63,10 @@ cleanup() {
 	sleep 5
 	stop $mds ${FORCE} $MDSLCONFARGS
     done
-    stop_lgssd
-    stop_lsvcgssd
     stop ost2 ${FORCE}
     stop ost ${FORCE}  --dump cleanup-dual.log
+    stop_lgssd
+    stop_lsvcgssd
 }
 
 if [ "$ONLY" == "cleanup" ]; then
@@ -79,6 +79,8 @@ setup() {
     gen_config
 
     start_krb5_kdc || exit 1
+    start_lsvcgssd || exit 2
+    start_lgssd || exit 3
     start ost --reformat $OSTLCONFARGS 
     PINGER=`cat /proc/fs/lustre/pinger`
 
@@ -89,8 +91,6 @@ setup() {
     fi
 
     start ost2 --reformat $OSTLCONFARGS 
-    start_lsvcgssd || exit 2
-    start_lgssd || exit 3
     [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
     for mds in `mds_list`; do
 	start $mds --reformat $MDSLCONFARGS
diff --git a/lustre/tests/replay-ost-single.sh b/lustre/tests/replay-ost-single.sh
index 398386d27fd8a898d0de8b3c3b156015d708555a..095ef8b8873fe20e6f1b51c333b66cf1b607ac72 100755
--- a/lustre/tests/replay-ost-single.sh
+++ b/lustre/tests/replay-ost-single.sh
@@ -53,6 +53,8 @@ cleanup() {
 	stop $mds ${FORCE} $MDSLCONFARGS
     done
     stop ost ${FORCE} --dump cleanup.log
+    stop_lgssd
+    stop_lsvcgssd
 }
 
 if [ "$ONLY" == "cleanup" ]; then
@@ -69,6 +71,9 @@ CLEANUP=${CLEANUP:-"cleanup"}
 setup() {
     gen_config
 
+    start_krb5_kdc || exit 1
+    start_lsvcgssd || exit 2
+    start_lgssd || exit 3
     start ost --reformat $OSTLCONFARGS
     [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
     for mds in `mds_list`; do
diff --git a/lustre/tests/replay-single.sh b/lustre/tests/replay-single.sh
index b2c2616943cb3608439add5b7214804a0df208c9..41aabf360cd635190fd9a4086809c4728f742bcf 100755
--- a/lustre/tests/replay-single.sh
+++ b/lustre/tests/replay-single.sh
@@ -66,10 +66,10 @@ cleanup() {
     for mds in `mds_list`; do
 	stop $mds ${FORCE} $MDSLCONFARGS
     done
-    stop_lgssd
-    stop_lsvcgssd
     stop ost2 ${FORCE} --dump cleanup.log
     stop ost ${FORCE} --dump cleanup.log
+    stop_lgssd
+    stop_lsvcgssd
 }
 
 if [ "$ONLY" == "cleanup" ]; then
@@ -85,10 +85,10 @@ setup() {
     gen_config
 
     start_krb5_kdc || exit 1
-    start ost --reformat $OSTLCONFARGS 
-    start ost2 --reformat $OSTLCONFARGS 
     start_lsvcgssd || exit 2
     start_lgssd || exit 3
+    start ost --reformat $OSTLCONFARGS 
+    start ost2 --reformat $OSTLCONFARGS 
     [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
     for mds in `mds_list`; do
 	start $mds --reformat $MDSLCONFARGS
diff --git a/lustre/tests/sanity-fid.sh b/lustre/tests/sanity-fid.sh
index 72942c7d108aacc0e5de8578b4948f20d2fc7785..2da851aafa34762fca110025987329ddc068bc92 100644
--- a/lustre/tests/sanity-fid.sh
+++ b/lustre/tests/sanity-fid.sh
@@ -37,21 +37,6 @@ MODE=${MODE:mds}
 
 . krb5_env.sh
 
-if [ $UID -ne 0 ]; then
-	RUNAS_ID="$UID"
-	RUNAS=""
-else
-	RUNAS_ID=${RUNAS_ID:-500}
-	RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
-fi
-
-if [ `using_krb5_sec $SECURITY` == 'y' ] ; then
-    start_krb5_kdc || exit 1
-    if [ $RUNAS_ID -ne $UID ]; then
-        $RUNAS ./krb5_refresh_cache.sh || exit 2
-    fi
-fi
-
 export NAME=${NAME:-local}
 
 SAVE_PWD=$PWD
diff --git a/lustre/tests/sanity-gns.sh b/lustre/tests/sanity-gns.sh
index b55312a354d7f5d8d59a801d17b30cc36dc8e7c8..0e079528f1540c6c5fd01dc08acd57ec9ecba008 100644
--- a/lustre/tests/sanity-gns.sh
+++ b/lustre/tests/sanity-gns.sh
@@ -38,21 +38,6 @@ PTLDEBUG=${PTLDEBUG:-0}
 
 . krb5_env.sh
 
-if [ $UID -ne 0 ]; then
-	RUNAS_ID="$UID"
-	RUNAS=""
-else
-	RUNAS_ID=${RUNAS_ID:-500}
-	RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
-fi
-
-if [ `using_krb5_sec $SECURITY` == 'y' ] ; then
-    start_krb5_kdc || exit 1
-    if [ $RUNAS_ID -ne $UID ]; then
-        $RUNAS ./krb5_refresh_cache.sh || exit 2
-    fi
-fi
-
 export NAME=${NAME:-local}
 
 SAVE_PWD=$PWD
diff --git a/lustre/tests/sanity-ldlm.sh b/lustre/tests/sanity-ldlm.sh
index e5bd4227e409c4c2716b20ad431dbd2b2d844dd5..68dbb0fd3b628d50c21ca7c870ef5106c30e6b13 100644
--- a/lustre/tests/sanity-ldlm.sh
+++ b/lustre/tests/sanity-ldlm.sh
@@ -8,6 +8,7 @@ PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
 MOUNT=${MOUNT:-/mnt/lustre}
 DIR=${DIR:-$MOUNT}
 export NAME=$NAME
+. krb5_env.sh
 clean() {
         echo -n "cln.."
         sh llmountcleanup.sh > /dev/null || exit 20
diff --git a/lustre/tests/sanity-lmv.sh b/lustre/tests/sanity-lmv.sh
index e31e0457c33b75a325772ee91936dc828391d2de..0a11ed7b7ce39c44c8d6312b34f0b5aa07b36605 100644
--- a/lustre/tests/sanity-lmv.sh
+++ b/lustre/tests/sanity-lmv.sh
@@ -44,21 +44,6 @@ PTLDEBUG=${PTLDEBUG:-0}
 
 . krb5_env.sh
 
-if [ $UID -ne 0 ]; then
-	RUNAS_ID="$UID"
-	RUNAS=""
-else
-	RUNAS_ID=${RUNAS_ID:-500}
-	RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
-fi
-
-if [ `using_krb5_sec $SECURITY` == 'y' ] ; then
-    start_krb5_kdc || exit 1
-    if [ $RUNAS_ID -ne $UID ]; then
-        $RUNAS ./krb5_refresh_cache.sh || exit 2
-    fi
-fi
-
 export NAME=${NAME:-lmv}
 
 SAVE_PWD=$PWD
diff --git a/lustre/tests/sanityN.sh b/lustre/tests/sanityN.sh
index 96532b774234fc4a434d761aa5d8390e63ef3690..576712b9e478104d1a3de21846b17be92d1e97cf 100644
--- a/lustre/tests/sanityN.sh
+++ b/lustre/tests/sanityN.sh
@@ -24,6 +24,8 @@ TOEXCL=${TOEXCL:-toexcl}
 TRUNCATE=${TRUNCATE:-truncate}
 export TMP=${TMP:-/tmp}
 
+. krb5_env.sh
+
 if [ $UID -ne 0 ]; then
 	RUNAS_ID="$UID"
 	RUNAS=""
@@ -32,6 +34,13 @@ else
 	RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
 fi
 
+if [ `using_krb5_sec $SECURITY` == 'y' ] ; then
+    start_krb5_kdc || exit 1
+    if [ $RUNAS_ID -ne $UID ]; then
+        $RUNAS ./krb5_refresh_cache.sh || exit 2
+    fi
+fi
+
 SAVE_PWD=$PWD
 
 clean() {