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