diff --git a/remmina/src/remmina_masterthread_exec.c b/remmina/src/remmina_masterthread_exec.c
index e6b03ee..3500b07 100644
--- a/remmina/src/remmina_masterthread_exec.c
+++ b/remmina/src/remmina_masterthread_exec.c
@@ -108,7 +108,8 @@ static gboolean remmina_masterthread_exec_callback(RemminaMTExecData *d)
 		case FUNC_VTE_TERMINAL_SET_ENCODING_AND_PTY:
 #if defined (HAVE_LIBSSH) && defined (HAVE_LIBVTE)
 			remmina_plugin_ssh_vte_terminal_set_encoding_and_pty( d->p.vte_terminal_set_encoding_and_pty.terminal,
-			        d->p.vte_terminal_set_encoding_and_pty.codeset, d->p.vte_terminal_set_encoding_and_pty.slave );
+			        d->p.vte_terminal_set_encoding_and_pty.codeset,
+			        d->p.vte_terminal_set_encoding_and_pty.master, d->p.vte_terminal_set_encoding_and_pty.slave );
 #endif
 			break;
 		}
diff --git a/remmina/src/remmina_masterthread_exec.h b/remmina/src/remmina_masterthread_exec.h
index 477616c..a0e9fa4 100644
--- a/remmina/src/remmina_masterthread_exec.h
+++ b/remmina/src/remmina_masterthread_exec.h
@@ -152,6 +152,7 @@ typedef struct remmina_masterthread_exec_data
 		{
 			VteTerminal *terminal;
 			const char *codeset;
+			int master;
 			int slave;
 		} vte_terminal_set_encoding_and_pty;
 #endif
diff --git a/remmina/src/remmina_ssh.c b/remmina/src/remmina_ssh.c
index 207732a..e02f6c8 100644
--- a/remmina/src/remmina_ssh.c
+++ b/remmina/src/remmina_ssh.c
@@ -1531,15 +1531,15 @@ remmina_ssh_shell_thread (gpointer data)
 		timeout.tv_usec = 0;
 
 		FD_ZERO (&fds);
-		FD_SET (shell->master, &fds);
+		FD_SET (shell->slave, &fds);
 
-		ret = ssh_select (ch, chout, shell->master + 1, &fds, &timeout);
+		ret = ssh_select (ch, chout, shell->slave + 1, &fds, &timeout);
 		if (ret == SSH_EINTR) continue;
 		if (ret == -1) break;
 
-		if (FD_ISSET (shell->master, &fds))
+		if (FD_ISSET (shell->slave, &fds))
 		{
-			len = read (shell->master, buf, buf_len);
+			len = read (shell->slave, buf, buf_len);
 			if (len <= 0) break;
 			LOCK_SSH (shell)
 			ssh_channel_write (channel, buf, len);
@@ -1571,7 +1571,7 @@ remmina_ssh_shell_thread (gpointer data)
 			}
 			while (len > 0)
 			{
-				ret = write (shell->master, buf, len);
+				ret = write (shell->slave, buf, len);
 				if (ret <= 0) break;
 				len -= ret;
 			}
diff --git a/remmina/src/remmina_ssh_plugin.c b/remmina/src/remmina_ssh_plugin.c
index aa84263..a7f6452 100644
--- a/remmina/src/remmina_ssh_plugin.c
+++ b/remmina/src/remmina_ssh_plugin.c
@@ -143,14 +143,14 @@ remmina_plugin_ssh_main_thread (gpointer data)
 	gpdata->shell = shell;
 
 	charset = REMMINA_SSH (shell)->charset;
-	remmina_plugin_ssh_vte_terminal_set_encoding_and_pty(VTE_TERMINAL (gpdata->vte), charset, shell->slave);
+	remmina_plugin_ssh_vte_terminal_set_encoding_and_pty(VTE_TERMINAL (gpdata->vte), charset, shell->master, shell->slave);
 	remmina_plugin_service->protocol_plugin_emit_signal (gp, "connect");
 
 	gpdata->thread = 0;
 	return NULL;
 }
 
-void remmina_plugin_ssh_vte_terminal_set_encoding_and_pty(VteTerminal *terminal, const char *codeset, int slave)
+void remmina_plugin_ssh_vte_terminal_set_encoding_and_pty(VteTerminal *terminal, const char *codeset, int master, int slave)
 {
 	TRACE_CALL("remmina_plugin_ssh_vte_terminal_set_encoding_and_pty");
 	if ( !remmina_masterthread_exec_is_main_thread() )
@@ -161,6 +161,7 @@ void remmina_plugin_ssh_vte_terminal_set_encoding_and_pty(VteTerminal *terminal,
 		d->func = FUNC_VTE_TERMINAL_SET_ENCODING_AND_PTY;
 		d->p.vte_terminal_set_encoding_and_pty.terminal = terminal;
 		d->p.vte_terminal_set_encoding_and_pty.codeset = codeset;
+		d->p.vte_terminal_set_encoding_and_pty.master = master;
 		d->p.vte_terminal_set_encoding_and_pty.slave = slave;
 		remmina_masterthread_exec_and_wait(d);
 		g_free(d);
@@ -182,9 +183,9 @@ void remmina_plugin_ssh_vte_terminal_set_encoding_and_pty(VteTerminal *terminal,
 	vte_terminal_set_delete_binding(terminal, VTE_ERASE_DELETE_SEQUENCE);
 
 #if !VTE_CHECK_VERSION(0,38,0)
-	vte_terminal_set_pty (terminal, slave);
+	vte_terminal_set_pty (terminal, master);
 #else
-	vte_terminal_set_pty (terminal, vte_pty_new_foreign_sync(slave, NULL, NULL));
+	vte_terminal_set_pty (terminal, vte_pty_new_foreign_sync(master, NULL, NULL));
 #endif
 
 }
diff --git a/remmina/src/remmina_ssh_plugin.h b/remmina/src/remmina_ssh_plugin.h
index 336bd9b..2d3b16c 100644
--- a/remmina/src/remmina_ssh_plugin.h
+++ b/remmina/src/remmina_ssh_plugin.h
@@ -46,7 +46,7 @@ void remmina_ssh_plugin_register(void);
 
 /* For callback in main thread */
 #if defined (HAVE_LIBSSH) && defined (HAVE_LIBVTE)
-void remmina_plugin_ssh_vte_terminal_set_encoding_and_pty(VteTerminal *terminal, const char *codeset, int slave);
+void remmina_plugin_ssh_vte_terminal_set_encoding_and_pty(VteTerminal *terminal, const char *codeset, int master, int slave);
 void remmina_plugin_ssh_vte_select_all (GtkMenuItem *menuitem, gpointer user_data);
 void remmina_plugin_ssh_vte_copy_clipboard (GtkMenuItem *menuitem, gpointer user_data);
 void remmina_plugin_ssh_vte_paste_clipboard (GtkMenuItem *menuitem, gpointer user_data);
