hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.29k stars 4.43k forks source link

Issues with shell when SSH-ing into Vagrant #9143

Closed mark1282 closed 6 years ago

mark1282 commented 7 years ago

Running Vagrant 2.0.1

Windows 7 (fully updated)

Using homestead so Ubuntu 16

I'll update the ticket with my vagrant file once I'm infront of my machine.

Debug output

Provide a link to a GitHub Gist containing the complete debug output: https://www.vagrantup.com/docs/other/debugging.html. The debug output should be very long. Do NOT paste the debug output in the issue, just paste the link to the Gist.

Expected behavior

Vagrant up appeared to run fine. However when SSH-ing into the Homestead box I got an issue.

Actual behavior

The default shell didn't load correctly. Left with a blank terminal screen

Steps to reproduce

  1. Vagrant up
  2. vagrant ssh
AntiTiming commented 7 years ago

Similar behavior for me with: Vagrant 2.0.1 Windows 10 cygwin (cygwin terminal)

I'm using the box 'ubuntu/xenial64'.

After the box is up and running, calling 'vagrant ssh' logs into the machine, shows all the information which is shown by ubuntu when logging in, but not the shell prompt. Worked with vagrant 2.0.0 without problems. Even without the prompt I can enter commands after logging into the box, but things like auto-completion, searching history etc. do not work.

FlipperPA commented 7 years ago

Same behavior here. I'm running:

Windows 10 - fully patched Vagrant 2.0.1 Virtualbox 5.2 bento/centos7.2

While vagrant ssh hangs, it does seem to be executing /etc/bashrc, as you can see virtualenvwrapper installing itself on the first time login for the user:

...
RUNNING HANDLER [vagrant_configure : restart network] **************************
changed: [default]

PLAY RECAP *********************************************************************
default                    : ok=56   changed=52   unreachable=0    failed=0

AEONFLUX@DESKTOP-3D4EIEA MINGW64 ~/Desktop/python-vagrant-centos7 (virtualbox-5.2)
$ vagrant ssh
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /home/vagrant/.virtualenvs/get_env_details
[after getting no bash prompt for 10 minutes, I hit Control+C here]

AEONFLUX@DESKTOP-3D4EIEA MINGW64 ~/Desktop/python-vagrant-centos7 (virtualbox-5.2)
$ vagrant ssh
[nothing, it just hangs here]

I will note, however, that if I SSH to the VM's hostname from PuTTy, I can get in and get a bash prompt. I'll test from work on my Mac as well. Here's the Vagrant file I'm using:

https://github.com/wharton/python-vagrant-centos7/blob/virtualbox-5.2/Vagrantfile

Thanks, as always, for your efforts!

voytass commented 7 years ago

I confirm: Win7 x64, Git 2.15.0.windows.1, Vagrant 2.0.1 - no shell prompt after vagrant ssh login. Login via PuTTY works fine.

FlipperPA commented 7 years ago

I've confirmed it works fine on my Mac. I'm wondering if it might be a terminal issue? I'm going to try setting git-bash to use xterm-256color like my Mac; will report back and try vagrant ssh -vvv.

FlipperPA commented 7 years ago

It seems to be a terminal issue. I'm able to vagrant ssh with my git-bash terminal set to xterm-256color but not when it is set to xterm.

For those looking for a workaround, click the icon in the git-bash terminal upper left, Options, Terminal and select xterm-256color in the Type dropdown.

AntiTiming commented 7 years ago

@FlipperPA Thank you, the workaround works for me as well!

I had my cygwin terminal set to xterm-color in my .bashrc which resulted in the login issue. Setting it to xterm-256color as proposed makes everything working as expected again.

BubbleSnap commented 7 years ago

Same issue, Windows 10 (build 1703), Vagrant 2.0.1, Git bash 2.15.0, Virtualbox 5.2.0. vagrant ssh from within git bash doesn't work. Using Putty or similar works, or using command via powershell or command prompt.

The terminal resey didn't seem to work for me.

lanshark commented 7 years ago

I am getting the same issue.

This is with git-bash, v2.9.0, virtualbox 5.1.30, and vagrant 2.0.1 on Windows 7 fully patched.

Using Powershell 5, it works with vagrant ssh. Windows cmd vagrant ssh works.

SSH (not vagrant ssh) to the 127.0.0.1 box from git command line, windows cmd, or Powershell works.

Only vagrant ssh fails. It does not provide a command prompt, and will not accept commands.

Loading the gui, and logging in there works.

Changing the terminal type to xterm-256color does not change the behaviour.

Updating to git-bash 2.15.0.windows.1 did not change anything

pomareb commented 7 years ago

Same issue here on windows 8, using cygwin, vagrant 2.0.1, while trying to launch debian/stretch64 wich was working fine on vagrant 1.8.5. My terminal is already on xterm-256color, cywing is up to date

dkelly-sighter commented 7 years ago

Hitting the same issue. Windows 10, Git V 2.9.2.windows.1, vagrant 2.0.1, Virtualbox 5.1.30. Work around with xterm-256color does not change behavior. However, I still get the welcome header on my ubuntu 14.04.5 LTS box and am able to navigate the file system, but no prompt:

image

FlipperPA commented 7 years ago

The workaround worked for me, but not a colleague. Another workaround: ssh vagrant@[hostname or IP] with password vagrant may work as well.

jk3us commented 7 years ago

For some reason, it isn't creating a pseudo terminal:

$ vagrant ssh web -- -vvv
OpenSSH_7.5p1, OpenSSL 1.0.2l  25 May 2017
debug1: Reading configuration data /etc/ssh/ssh_config
Pseudo-terminal will not be allocated because stdin is not a terminal.   <----
debug2: resolving "127.0.0.1" port 2222
...

A more general workaround is to dump vagrant's ssh config and tell ssh to use it:

$ vagrant ssh-config > .vagrant_ssh.conf
$ ssh -F .vagrant_ssh.conf default   # where default is the name of your box, 
jk3us commented 7 years ago

Now I see that vagrant ships with an msys environment, and it's running that ssh and not cygwin's by default, which is apparently problematic when calling from inside cygwin. If I call that ssh.exe directly (/cygdrive/C/HashiCorp/Vagrant/embedded/usr/bin/ssh -F .vagrant_ssh_config web), I get the same behavior.

You can tell Vagrant to prefer your system tools with the VAGRANT_PREFER_SYSTEM_BIN environment variable, which seems to fix this problem (for me):

VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh

or put this into your .bash_profile:

export VAGRANT_PREFER_SYSTEM_BIN=1
pomareb commented 7 years ago

Nice, the VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh worked just fine for me

ghost commented 7 years ago

Hi everyone, I'm trying to vagrant ssh to create a new database with mysql, the above command worked for me, but now I'm stucked in the password field. It just wont take anything, is like if the keyboard wasn't working when I type the pass.

Eduardo's PC@LAPTOP-7MVVJUG0 MINGW64 ~/Documents/Root/local-sites
$ node --version
v8.9.1

Eduardo's PC@LAPTOP-7MVVJUG0 MINGW64 ~/Documents/Root/local-sites
$ npm --version
5.5.1

Eduardo's PC@LAPTOP-7MVVJUG0 MINGW64 ~/Documents/Root/local-sites
$ git --version
git version 2.15.0.windows.1

I'm running Git Bash as admin (and tried with no admin privileges). Windows command line and Node.js command prompt, and Windows Powershell do the same thing when I get to the password field.

Windows 10 - 64bit

I would really appreciate any help on this matter.

Thank you!

screenshot

vovkvlad commented 6 years ago

Guys, I have the same problem but on macOS Sierra 10.12.6, after running vagrant ssh pseudo terminal is not invoked: image

I tried setting VAGRANT_PREFER_SYSTEM_BIN system variable to 1 - it did not help in my case.

UPDATE: running bash -i worked for me once, but after that I encountered the same issue and running bash -i thing does not making a thing anymore....

fraserredmond commented 6 years ago

VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh (and ssh vagrant@[hostname or IP]) worked for me, but xterm-256color didn't.

Hoping for a proper fix :)

nospamcalfee commented 6 years ago

Hi, I had a similar problem on Windows 7 - do "vagrant ssh" and it zipped to the next line and did not start vagrant. I could directly ssh vagrant@127.0.0.1 etc!

What I found is I had (BOTH!) cygwin and msys in my path and they both has ssh.exe programs. I removed them from the path and now vagrant ssh works. So something requires that the internal ssh and presumably the hidden .ssh directory must be in the hashicorp\ directory tree.

alelavoie commented 6 years ago

VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh (and ssh vagrant@[hostname or IP]) worked for me, but xterm-256color didn't.

Same here

zach007 commented 6 years ago

i got the same problem ~ i was wondering what was wrong for a week . vagrant version : 2.0.1 windows 10 virtualbox : 5.1.30 git bash : 2.15

  1. when i use git bash , VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh works for me ~ but sometimes when i typed ,git bash crashed zia x96 r86 0v 1u65

2.and when i use powershell it seems ok to show prompt,but while using vim(plugin : vim-haskell-now), the color has some problem 4y m btxxwsu6 hyald 78e6sfkeywi 8vv4u m h

ghost commented 6 years ago

The best solution for me is to use:

Otherwise our developers on windows can't run there virtual machine correctly.

leandroruel commented 6 years ago

just coming here to say it: i typed vagrant up and provision in git bash, but not worked to me, he freezes and stops on it:

$ vagrant ssh
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-101-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.

typed vagrant ssh on Windows Power Shell, that worked normally. this no make sense to me. windowspowershell-vagrantssh

toothbrush7777777 commented 6 years ago

@leandroruel The workaround described by @jk3us works perfectly for me with Git Bash.

VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh
velletti commented 6 years ago

I stuck in the same issue since Windows 10 Creators Update. also older boxes, that had worked perfect in the past, did not show up the bash prompt.

my solution: I Installed latest git for windows Version (2.15.1.2-64 bit ) again and during installation process, i select "Use Window default console window" (cmd.exe) instead of "MinTTY"

PS: i did not try the other workarounds above.

alelavoie commented 6 years ago

For no apparent reason, it now works for me without specifying the VAGRANT_PREFER_SYSTEM_BIN=1 flag.

rhenann commented 6 years ago

Same issue here

Environment:

Solved using this: VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh

Thanks @jk3us

PickledDragon commented 6 years ago

+1 Same issue for me too

Workaround with VAGRANT_PREFER_SYSTEM_BIN=1 is good.

mumukiller commented 6 years ago

Same issue:

Workaround with VAGRANT_PREFER_SYSTEM_BIN=1 did not help

rhenann commented 6 years ago

The workaround with VAGRAT_PREFER_SYSTEM_BIN=1 is freezing my git bash. Another solution is to connect to vagrant with putty (or kitty).

Like this: https://github.com/Varying-Vagrant-Vagrants/VVV/wiki/Connect-to-Your-Vagrant-Virtual-Machine-with-PuTTY

dynasty919 commented 6 years ago

the VAGRANT_PREFER_SYSTEM_BIN=1 method is awesome! totally works for me.

ctmarc commented 6 years ago

Similar issue here: When accessing the box with vagrant ssh via git bash, the shell prompt remains invisible. My input and the console output are shown as expected, except that the up button moves the cursor in the console instead of loading the last typed command. Running vagrant up has another issue, the box still shows as "powered down" on the VirtualBox GUI.

When I use the Windows Command prompt for vagrant up and vagrant ssh, everything works perfectly.

activemkaye commented 6 years ago

Wow this is super annoying. I can't get it to automatically apply this variable by following this suggestion, So I have to manually prepend it to the SSH command. I hope someone fixes this soon

opreani commented 6 years ago

VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh works perfect

meggangreen commented 6 years ago

just chiming in to say the VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh works for me as well

sefeist commented 6 years ago

I noticed a comment in the Git for Windows v2.15.1(2) release notes:

Some console programs, most notably non-MSYS2 Python, PHP, Node and OpenSSL, interact correctly with MinTTY only when called through winpty (e.g. the Python console needs to be started as winpty python instead of just python).

winpty vagrant ssh solved the problem for me. Not that a real fix wouldn't be better.

codebymikey commented 6 years ago

I ended up adding

alias vagrant='VAGRANT_PREFER_SYSTEM_BIN=1 vagrant'

to my .bashrc then calling source ~/.bashrc and I was golden.

You can ignore the alias by running \vagrant ssh instead of vagrant ssh

@sefeist thanks for the added info. Hopefully someone can get to the bottom of this!

activemkaye commented 6 years ago

@codebymikey I followed your instructions and when I do \vagrant ssh, I still get the interface without bash. I added the alias at the bottom of my .bashrc file. Does it matter where in the file it goes as long as it's not within a conditional? Thanks.

codebymikey commented 6 years ago

@activemkaye You should run vagrant ssh.

\vagrant is used to ignore the alias we just added in the bashrc (in case you ever need to), and runs the original vagrant executable file which still has the terminal issues.

activemkaye commented 6 years ago

@codebymikey Yea I tried both ways. The issue persists.

zulkafilabbas commented 6 years ago

Ran into the same problem when I was following instructions for setting up the environment for Udacity's Shell.

VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh worked for me. xterm-256 color option had no effect.

Software Version Details:

  1. Virtual Box Version 5.2.6 r120293 (Qt5.6.2)
  2. Vagrant 2.0.1
  3. Windows 10 Pro 64-bit (10.0, Build 16299) (16299.rs3_release.170928-1534)
  4. Git version 2.16.1.windows.1
iainhallam commented 6 years ago

Same problem here, with these versions:

Windows 10 Pro 64-bit version 1709, build 16299.15 Git Bash 2.8.3.windows.1 Vagrant 2.0.1 VirtualBox 5.1.32

Using winpty vagrant ssh worked to get back a command prompt on Scotch Box, as did VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh. My Git Bash terminal was already set to xterm-256color.

mark1282 commented 6 years ago

Updated to Vagrant 2.0.2 and it seems to have fixed the issue for me. Hopefully it's resolved it for others too?

chrisroberts commented 6 years ago

Hi there. The 2.0.2 release of Vagrant has an updated approach to the ssh client. The installer package ships with its own vendored ssh client so things are functional if the user has not yet installed an SSH package. This caused issues in special environments like cygwin or msys2, which could be rectified with wrapping the ssh process within a winpty process. However, this was also fragile and did not consistently work in all setups. So the 2.0.2 release removed the winpty wrapping and will search first for an ssh client on the host's path, and then fall back to the vendored ssh client as a last resort.

Apologies for the troubles encountered within different shell environments. This update should resolve most of the issues that were encountered.

Cheers!

HSarode-Compumatrice commented 6 years ago

hey guys, my vagrant ssh freezes like below, $ vagrant ssh Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-112-generic x86_64)

0 packages can be updated. 0 updates are security updates. . . . . any suggestion please, and also didn't understand where to apply "VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh" in vagrantfile or where. thankyou

FlipperPA commented 6 years ago

@HSarode-Compumatrice This was fixed in version 2.0.2 - upgrade Vagrant. :)

HSarode-Compumatrice commented 6 years ago

hey @FlipperPA Thank you so much,upgrading vagrant it worked,it basically for ubuntu xenial 16.04.3 box !!!

grahamh commented 6 years ago

I had a similar problem with the latest version of Vagrant 2.0.2 running on Windows 7 host, with Archlinux/Arlinux box. The prompt appeared intermittently and was sometimes corrupted. I installed OpenSSH for windows from http://www.mls-software.com/opensshd.html and all seems good now.

c-gregory commented 6 years ago

I am having this same problem. I have tried installing cygwin and using VAGRANT_PREFER_SYSTEM_BIN=1 but the prompt is still blank. Also tried uninstalling and redownloading Vagrant and VirtualBox with no luck.

OS: Win 7 Home Premium Version 6.1 (Build 7601: Service Pack 1) Virtual Box Verison: Version 5.2.97 r120712 (Qt5.6.2) Vagrant Version: 2.0.2 PowerShell: 5.1.14409.1012

kylegibson commented 6 years ago

My team and I have been experiencing this issue frequently recently. The hosts we've been using are ubuntu and macos, the guest is always ubuntu 16.04.

The versions of vagrant I've tested: 2.0.2, 1.95. Versions of virtualbox I've tested, 5.2.8, 5.2.6, 5.2.0, 5.1.34

I'm commenting now because the hang happened again, and VAGRANT_PREFER_SYSTEM_BIN=1 does not fix the issue for me:

> VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh -- -vvv
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /home/kyle/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: auto-mux: Trying existing master
debug1: Control socket "/tmp/127.0.0.12222vagrant" does not exist
debug2: ssh_connect: needpriv 0
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 2222.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/kyle/dev/xxxxx/.vagrant/machines/dev/virtualbox/private_key" as a RSA1 public key
debug1: identity file /home/kyle/dev/xxxxx/.vagrant/machines/dev/virtualbox/private_key type -1
debug1: identity file /home/kyle/dev/xxxxx/.vagrant/machines/dev/virtualbox/private_key-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
<hang>
ssh_exchange_identification: read: Connection reset by peer

The vagrant up looks like this:

==> dev: Clearing any previously set network interfaces...
==> dev: Preparing network interfaces based on configuration...
    dev: Adapter 1: nat
    dev: Adapter 2: hostonly
==> dev: Forwarding ports...
    dev: 8000 (guest) => 8000 (host) (adapter 1)
    dev: 3306 (guest) => 3306 (host) (adapter 1)
    dev: 8888 (guest) => 8888 (host) (adapter 1)
    dev: 22 (guest) => 2222 (host) (adapter 1)
==> dev: Running 'pre-boot' VM customizations...
==> dev: Booting VM...
==> dev: Waiting for machine to boot. This may take a few minutes...
    dev: SSH address: 127.0.0.1:2222
    dev: SSH username: vagrant
    dev: SSH auth method: private key
<hang>

After the default boot-timeout (300 seconds), this happens:

Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

When SSH does not hang, the delay for SSH working is about 5 seconds.

fpilee commented 6 years ago

the fix is for when you successfully login but there is no prompt.