Problem
When running apt-get install
in an non-interactive SSH session, the session never closes. Example:
ssh user@target "sudo apt-get -y install my_package"
The my_package
does get installed properly, but the SSH session just dangles open.
Question
Is there any flag to pass SSH to get apt-get
to work?
Additional Information
Context
Remote installation is used for automated deployment of a package on an integration server. As soon as we push some code changes to a repository, a job pulls in the code, builds the package, and deploys it on integration to check that everything works well (as far as deployment is concerned).
Already Tried & Notes
- The same SSH session executing
apt-get update
closes cleanly. Note thatapt-get update
is not interactive, whereasapt-get install
is. This may suggest that interactivity is an issue. - A command like
ssh user@target "sudo apt-get install my_package && echo Hello"
never reaches theecho
. debconf
complains that it cannot find a nice frontend (Display, Readline), and it falls back to Teletype (although Readline is available).- In relation to debconf's frontend, passing
-t
to force TTY with SSH does not help. NeitherDEBIAN_FRONTEND=noninteractive
. - All was done on Ubuntu 12_04 LTS.
Best Answer
The following answer on SF did the trick:
ssh fails to execute remote command when run from cron bash script
The
-t
flag forces a pseudo-tty allocation, except perhaps when there is no TTY locally. But passing the flag twice like in-t -t
just pretends to do it. And that solved the problem.See the SSH documentation:
Now, why did that work? It turns out that
debconf
does not complain anymore about the frontend in the logs. So I believe that the double-t
sets (lures?)debconf
as needed, which allowsapt-get install
completion to end the SSH session cleanly.