diff --git a/svr-chansession.c b/svr-chansession.c
index cb5acda2c7f08e5d7c8093c194fd16d464851eda..2664382e54bf0549b8577ba3c116fdbfb734e85c 100644
--- a/svr-chansession.c
+++ b/svr-chansession.c
@@ -742,8 +742,6 @@ static int ptycommand(struct Channel *channel, struct ChanSess *chansess) {
 		login_login(li);
 		login_free_entry(li);
 
-		m_free(chansess->tty);
-
 #ifdef DO_MOTD
 		if (svr_opts.domotd) {
 			/* don't show the motd if ~/.hushlogin exists */
@@ -884,9 +882,10 @@ static void execchild(void *user_data) {
 		addnewvar("TERM", chansess->term);
 	}
 
-	printf("adding option %p %s\n", ses.authstate.pubkey_options,
-			ses.authstate.pubkey_options->original_command);
-
+	if (chansess->tty) {
+		addnewvar("SSH_TTY", chansess->tty);
+	}
+	
 #ifdef ENABLE_SVR_PUBKEY_OPTIONS
 	if (ses.authstate.pubkey_options &&
 			ses.authstate.pubkey_options->original_command) {