why does screen cause problems with sftp?

1

I love to use screen, but I haven't really had much experience using it over ssh. At work I recently was issued a shell account and I decided to try to configure it so that screen gets run when I login. I'm logging in remotely via ssh with putty.

Anyway, I had two methods that both seemed to work pretty well:

  1. configured putty to run /usr/bin/screen -R upon connecting and
  2. added this line to my .bashrc: if [ -z "$STY" ]; then /usr/bin/screen -R; fi

The problem is that later on I tried to scp some files I couldn't connect. It said "Must be connected to a terminal". I also tried Filezilla and it had major connection problems. I did some googling and apparently I'm not the first person that's had sftp get messed up by trying to use screen as a login shell. http://winscp.net/forum/viewtopic.php?t=1715

I was wondering if anybody could provide some insight into why this is happening because I really have no clue and I would be interested to understand it and maybe find a workaround.

shwoseph

Posted 2014-01-18T02:22:42.793

Reputation: 151

Answers

3

You should put anything related to login shells into ~/.bash_profile and things related to interactive (non-login) shells into ~/.bashrc. From the manual page of bash(1):

   ~/.bash_profile
          The personal initialization file, executed for login shells
   ~/.bashrc
          The individual per-interactive-shell startup file

So, instead of just symlinking ~/.bashrc to ~/.bash_profile (or vice versa), you should have two separate files which have somewhat different things in them.

Put [ -z "$STY" ] && then /usr/bin/screen -R only in ~/.bash_profile and then you'll get screen run only when you're actually logging in instead of getting screen run every time you spawn an interactive shell (I don't have scp sources at hand right now but have a faint memory of it actually spawning a shell so that the shell spawned processes ~/.bashrc).

Sami Laine

Posted 2014-01-18T02:22:42.793

Reputation: 1 002

Thanks. I didn't even think of that, but it makes sense. If scp is processing bashrc and opening a screen session, I guess it might produce some unexpected behavior. – shwoseph – 2014-01-20T03:38:32.780