d78d34
diff --git a/auth-krb5.c b/auth-krb5.c
d78d34
index 2b02a04..19b9364 100644
d78d34
--- a/auth-krb5.c
d78d34
+++ b/auth-krb5.c
def1de
@@ -375,5 +375,21 @@ cleanup:
def1de
 		return (krb5_cc_resolve(ctx, ccname, ccache));
def1de
 	}
d78d34
 }
def1de
+
d78d34
+/*
d78d34
+ * Reads  k5login_directory  option from the  krb5.conf
d78d34
+ */
d78d34
+krb5_error_code
d78d34
+ssh_krb5_get_k5login_directory(krb5_context ctx, char **k5login_directory) {
d78d34
+	profile_t p;
d78d34
+	int ret = 0;
d78d34
+
d78d34
+	ret = krb5_get_profile(ctx, &p);
d78d34
+	if (ret)
d78d34
+		return ret;
d78d34
+
d78d34
+	return profile_get_string(p, "libdefaults", "k5login_directory", NULL, NULL,
d78d34
+		k5login_directory);
d78d34
+}
def1de
 #endif /* !HEIMDAL */
def1de
 #endif /* KRB5 */
d78d34
diff --git a/auth.h b/auth.h
d78d34
index f9d191c..c432d2f 100644
d78d34
--- a/auth.h
d78d34
+++ b/auth.h
d78d34
@@ -222,5 +222,7 @@ int	 sys_auth_passwd(Authctxt *, const char *);
d78d34
 #if defined(KRB5) && !defined(HEIMDAL)
d78d34
 #include <krb5.h>
117678
 krb5_error_code ssh_krb5_cc_new_unique(krb5_context, krb5_ccache *, int *);
d78d34
+krb5_error_code ssh_krb5_get_k5login_directory(krb5_context ctx,
d78d34
+	char **k5login_directory);
d78d34
 #endif
d78d34
 #endif
d78d34
diff --git a/gss-serv-krb5.c b/gss-serv-krb5.c
d78d34
index a7c0c5f..df8cc9a 100644
d78d34
--- a/gss-serv-krb5.c
d78d34
+++ b/gss-serv-krb5.c
d78d34
@@ -244,8 +244,27 @@ ssh_gssapi_k5login_exists()
d78d34
 {
d78d34
 	char file[MAXPATHLEN];
d78d34
 	struct passwd *pw = the_authctxt->pw;
d78d34
+	char *k5login_directory = NULL;
d78d34
+	int ret = 0;
d78d34
+
d78d34
+	ret = ssh_krb5_get_k5login_directory(krb_context, &k5login_directory);
d78d34
+	debug3("%s: k5login_directory = %s (rv=%d)", __func__, k5login_directory, ret);
d78d34
+	if (k5login_directory == NULL || ret != 0) {
d78d34
+		/* If not set, the library will look for  k5login
d78d34
+		 * files in the user's home directory, with the filename  .k5login.
d78d34
+		 */
d78d34
+		snprintf(file, sizeof(file), "%s/.k5login", pw->pw_dir);
d78d34
+	} else {
d78d34
+		/* If set, the library will look for a local user's k5login file
d78d34
+		 * within the named directory, with a filename corresponding to the
d78d34
+		 * local username.
d78d34
+		 */
d78d34
+		snprintf(file, sizeof(file), "%s%s%s", k5login_directory, 
d78d34
+			k5login_directory[strlen(k5login_directory)-1] != '/' ? "/" : "",
d78d34
+			pw->pw_name);
d78d34
+	}
d78d34
+	debug("%s: Checking existence of file %s", __func__, file);
d78d34
 
d78d34
-	snprintf(file, sizeof(file), "%s/.k5login", pw->pw_dir);
d78d34
 	return access(file, F_OK) == 0;
d78d34
 }
d78d34
 
d78d34
diff --git a/sshd.8 b/sshd.8
d78d34
index 5c4f15b..135e290 100644
d78d34
--- a/sshd.8
d78d34
+++ b/sshd.8
d78d34
@@ -806,6 +806,10 @@ rlogin/rsh.
d78d34
 These files enforce GSSAPI/Kerberos authentication access control.
d78d34
 Further details are described in
d78d34
 .Xr ksu 1 .
d78d34
+The location of the k5login file depends on the configuration option
d78d34
+.Cm k5login_directory
d78d34
+in the
d78d34
+.Xr krb5.conf 5 .
d78d34
 .Pp
d78d34
 .It Pa ~/.ssh/
d78d34
 This directory is the default location for all user-specific configuration