4

I would to take in some login information for a script have written in to be used by many users. In python I set the input_raw to read from dev/tty but it fails horribly when i am connecting to the script being run on a server through ssh.

Thoughts? Workarounds?

I would prefer to avoid hard coding usernames into the script.

Please and thank you.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
Mahdi Yusuf
  • 19,931
  • 26
  • 72
  • 101

1 Answers1

5

Try using the -t option to ssh:

     -t      Force pseudo-tty allocation.  This can be used to execute arbi-
             trary screen-based programs on a remote machine, which can be
             very useful, e.g. when implementing menu services.  Multiple -t
             options force tty allocation, even if ssh has no local tty.

There doesn't seem to be an equivalent option in ~/.ssh/config, so you will need to create a shell script. A simple one is:

#!/bin/sh

ssh -t "$*"

Save this as ssh-t or something, chmod +x ssh-t, and put it somewhere in your PATH. Then set GIT_SSH=ssh-t to tell Git to use this script.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • That probably would have worked, but I am starting that ssh connection through a git push. Is there a way to inject the -t option? – Mahdi Yusuf Jul 30 '10 at 14:56
  • @garbagecollector: The [GIT_SSH](http://www.kernel.org/pub/software/scm/git/docs/) environment variable tells Git which command to use for ssh. As explained on that page, to pass options to ssh you can wrap it in another shell script, or use `~/.ssh/config` (I'd recommend the latter). – Greg Hewgill Jul 30 '10 at 21:37
  • @garbagecollector: According to [SSH - How to include “-t command” in the ~/.ssh/config file](http://serverfault.com/questions/56086/ssh-how-to-include-t-command-in-the-ssh-config-file), there doesn't seem to be an equivalent config option for -t. I would create a shell script instead (see edited answer). – Greg Hewgill Aug 03 '10 at 20:26
  • 1
    You probably want to use "$@" instead of "$*", so that separate arguments to ssh-t don't get grouped into one argument to ssh. – Evan Krall Jun 30 '11 at 18:06
  • you can add an alias as " alias ssh-t='ssh -t' " at the end of "~/.profile" and then run "source ~/.profile" – Abhi Oct 09 '22 at 14:41