Could not resolve host: github.com ONLY in windows bash - bash

I have installed ubuntu 18.04(WSL) in my win 10 64 bit, 1903.
For the command git clone https://github.com/facebookresearch/fastText.git,
it works well in git bash(git for windows) and ubuntu 18.04 shell but not in bash (C:\Windows\System32\bash.exe), the error message is
$ git clone https://github.com/facebookresearch/fastText.git
Cloning into 'fastText'...
fatal: unable to access 'https://github.com/facebookresearch/fastText.git/': Could not resolve host: github.com
I have only two .gitconfig file in my pc, one for git bash and another for ubuntu 18.04 shell. I think ubuntu 18.04 shell may equal to bash in some degree but the bash must have problems.

It could be that your /etc/resolv.conf file is corrupt - it happened to me!
Symptoms are:
Inside WSL /etc/resolv.conf is not plain text but some binary garbage. It should be plain text.
You cannot e.g. ping google.com or ping stackoverflow.com from inside WSL.
You can ping those domains OK from powershell in the windows host. Windows git also works OK.
Aside: Interestingly ping github.com fails for me today on all my machines but that doesn't stop me from visiting github in my browser or using git - strange.
The solution is to sudo rm /etc/resolv.conf and restart WSL - windows will recreate that file for you and you should be able to ping away and use git once more from within WSL.
To restart WSL - open a Powershell terminal in Administrator mode and run the following commands. (taken from #germa-vinsmoke 's answer)
wsl --shutdown
Get-Service LxssManager | Restart-Service

Edit your wsl.conf
sudo nano /etc/wsl.conf
[network]
generateResolvConf = false
Save this file and exit. Then edit /etc/resolv.conf.
sudo nano /etc/resolv.conf
Add/Edit this line
nameserver 1.1.1.1
Then close your WSL console. Open Powershell with admin and shutdown the wsl.
wsl --shutdown
At last, restart the wsl service
Get-Service LxssManager | Restart-Service
More info - WSL2 - No internet connectivity. DNS Issues(Temporary failure in name resolution)
Edit 1 By P.hunter:
When your are behind an VPN, you need to set your nameserver to same what the VPN provides.
For that -
Go to Network Status (On Windows) and click on change adapter settings.
Find the adapter of your VPN, right click on it and open properties.
Find IpV4 option from the dropdown, and open it.
Find the DNS mentioned and use the same in Step 3.

None of the above answers worked for me. But this answer from this Github thread did. Reposting for ease:
It seems launching the VSCode daemon messes things up
Make this your /etc/wsl.conf file
[network]
generateResolvConf = false
Shutdown wsl
wsl --shutdown
Start wsl and create the file: /etc/resolv.conf containing
nameserver 8.8.8.8
P.S. if this answer doesn't help, others on the Github thread might!

I can assume that you have problems with proxying.
Try it:
git config --global --unset http.proxy
git config --global --unset https.proxy
Similar problem: #20370294 and #5377703

I did the following step to resolve the issue:
Check the connection to the internet.
ping stackoverflow.com
Edit /etc/resolv.conf, in my case the reason is due to the nameserver 172.22.16.1
sudo vim /etc/resolv.conf
add the nameserver to point to google server
nameserver 8.8.8.8
nameserver 8.8.4.4
and add a comment to the original nameserver by adding #
Repeat step 1 to cross-check the connection again.
Hope this helps!

Related

Cannot clone git repo un EC2 iNSTANCE

I used the following command and tried to clone a repo but unfortunately the following error pops up. I cannot go further
ubuntu#ip-add-rr-ee-ss:~$ git clone https://github.com/repo/file.git
Cloning into 'file'...
fatal: unable to access 'https://github.com/repo/file.git/': Could not resolve host: github.com
Could not resolve host
This must be due to DNS issue on your EC2 instance (I can see that you're using Ubuntu here)
You can try to use curl to test the connection to that URL first
Check the DNS configuration: cat /etc/resolv.conf
If possible, you
should replace your current DNS setting with others DNS like google
(8.8.8.8 & 8.8.4.4)
Try to edit that file: vi /etc/resolv.conf
You
should insert/edit the following into:
nameserver 8.8.8.8
nameserver 8.8.4.4
Save the file by clicking [Esc] and type :wq
I fixed the problem once I added the following to my outbound connection for my group security setting:
Type: All traffic
Protocol: All
ip: 0.0.0.0/0
This also fixed my sudo yum install issues too.

mac autocomplete for ssh hosts in terminal

I had used Ubuntu for a while and I have configured ssh aliases for hosts I need to connect through ssh. A few days ago I started using mac book and I moved all ssh info (keys, config) onto my mac. But when I'm typing ssh project_ and press TAB it does not show possible hostnames, and even when I'm typing ssh project_sta and TAB, autocompletion not working. But when I'm typing the full name like ssh project_staging it works, so I assume that everything is okay with the config file
I tried to use the original mac terminal and iterm2, same issue on both. Also, I asked other guys who work on mac, and ssh autocompletion works for them.
My ssh config:
Host project_staging
HostName xxxxx
User xxxx
Port xxxx
Host project_production
HostName xxxx
User xxxxx
Port xxxx
In real life, I have much more hosts and it's hard to remember all of them.
Any ideas, thank you!
okay, I solve it by adding zsh with oh_my_zsh and add ssh as a plugin to a .zshrc file

Docker error on Windows 2016 "Client.Timeout exceeded while awaiting headers"

I get the following error when I try to do "docker run" on my Windows 2016.
PS C:\Users\Administrator> docker run microsoft/sample-dotnet
Unable to find image 'microsoft/sample-dotnet:latest' locally
C:\Program Files\Docker\docker.exe: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'C:\Program Files\Docker\docker.exe run --help'.
I followed the instructions here to get started.
This is different from this question because this is Windows.
Any ideas?
same Problem for Windows. Some people wrote to delete dns 8.8.8.8 from resolve.conf
But i added this dns to my Settings (right click on docker icon -> Network -> Set DNS to Fixed (8.8.8.8)
Go to Docker settings > network > DNS server . change from automatic to fixed ( default is 8.8.8.8 ) . worked on win 10
It turns out I needed to set the proxy as per this link.
Here is an example of what I had to do (replacing my proxy address):
[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://myproxy:80/", [EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("HTTPS_PROXY", "https://myproxy:80/", [EnvironmentVariableTarget]::Machine)
restart-service docker
Kindly launch the docker setting and set your dns to 8.8.8.8
So I faced the same problem and it took me days to figure out what to do.
Summary:
I disabled Hyper-V (from the Hyper-V Manager, that comes with docker-desktop)
I disabled every Network Adapter that is a part of Hyper-V (vEthernet(DockerNAT), vEthernet(Default Switch) and Virtual-Box-Host-Only Network)
In the Docker Settings, I set the DNS to 8.8.8.8
In the Docker Settings, I set Proxy to no-Proxy
In the General Docker Settings, I checked "Expose Daemon on tcp[..]"
I reactivated the following network adapters: vEthernet(DockerNAT), vEthernet(Default Switch) and Virtual-Box-Host-Only Network
I restarted (enabled) Hyper-V
I restarted Docker
In my console I tried docker run hello-world
Pull works! Login works! Everything works! -> Time to get a coffee
Ubuntu, Centos
Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that
mkdir -p /etc/systemd/system/docker.service.d
sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf
adds the HTTP_PROXY environment variable:
[Service]
Environment="HTTP_PROXY=http://172.28.5.202:3128/"
Or, if you are behind an HTTPS proxy server, create a file called
/etc/systemd/system/docker.service.d/https-proxy.conf that adds the HTTPS_PROXY environment variable:
[Service]
Environment="HTTPS_PROXY=http://172.28.5.202:3128/"
Flush changes:
$ sudo systemctl daemon-reload
Restart Docker:
$ sudo systemctl restart docker
It worked!

Vagrant, Ansible, and SSH forwarding

I'm trying to use Vagrant and Ansible to create a developer VM environment. I'm able to connect just fine and install packages. My issue seems to be with ssh, git, and keyfiles. My setup is unfortunately rather complicated, and I don't have the ability to change that. The git repositories are hosted on a machine that I have to connect to via a bastion host with a keyfile.
My local ssh config file has all the necessary proxy commands to make this work. I have SSH forwarding my key, because I can log into the VM manually and use git. Via Ansible it doesn't seem to know about hosts that should be setup via the ssh config file.
I am not running the git clone as sudo, and I am using accept_hostkey. It just doesn't seem to know about the repository host at all.
I have also tried adding an ansible.cfg with the following command:
ssh_args = -o ControlPersist=15m -F ssh.config -q
The ssh.config file is the same as my ~/.ssh/config that happens to work when doing the git clones manually. I'm also doing this as the vagrant user manually, and I have remote_user set to vagrant in my playbook.
I'm just kind of stumped as to how this is supposed to work.
If I understand correctly, you can do it manually git clone into your vagrant machine?
If yes, then you can do like this, as you have already told us that the both machine has exactly the same ~/.ssh/config file, then you can do like this which I did during the git clone, when I got error:
- name: Pull sources from the repository.
git: repo='git#bitbucket.org:test/test.git' version=master dest=/var/www accept_hostkey=True force=yes recursive=no key_file=~/.ssh/id_rsa
Sometime, explicitly defined the key_file, accept_hostkey=True and force=yes solve the problem.
On the other hand, if you want to explicit define that always us the ssh connection instead of paramiko, then you can set into your ansible.cfg file, which is located at /etc/ansible/ansible.cfg
[defaults]
transport=ssh
There is another technique that I have read somewhere, you can also try that please to teach Ansible to talk to Git server on your behalf (again this change is in /etc/ansible/ansible.cfg)
[ssh_connection]
ssh_args = -o ForwardAgent=yes
Hope this will help you. Thanks
I'm not too familiar with Ansible but from docs, Ansible supports 2 ssh transports: OpenSSH, Paramiko (Python's SSH).
Unless you manually choose which one to use, it might choose Paramiko instead of OpenSSH.
This can explain the troubles you are having, since ssh_args is OpenSSH specific setting.
So the issue turned out to be that I was actually running one of my git clones as root after all.
For the SSH key to be forwarded properly in that case, you have to edit /etc/sudoers (with visudo) and update env_keep so that SSH_AUTH_SOCK is preserved.

use ssh private key from host in vagrant guest

I want to clone a bunch of private git repositories while provisioning a vagrant box. According to this article this should be possible using config.ssh.forward_agent = true. However, when trying to connect to github via something like ssh -T git#github.com -o StrictHostKeyChecking=no it fails with the following error:
Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
Permission denied (publickey).
I cut my configuration down to the simplest possible configuration. You can find it here: https://gist.github.com/TomTasche/31f7c45fcffc2997d43a
When I do "vagrant ssh" and try the same again, a similar error occurs:
Cloning into 'private-repositories'...
Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Edit: the configuration linked above does work on a host running Ubuntu, but does neither work on a Mac host, nor on a Windows host. My goal is to have a configuration that works on all these three hosts.
Please check whether your host system has ssh-agent forwarding enabled. You can do so for example by adding this block to your ~/.ssh/config file:
Host *
ForwardAgent yes
If this is enabled vagrant ssh (and also vagrant provision) should be able to forward your key to the guest machine.
You also might want to check using ssh-add -l whether your ssh-agent does know about your SSH-key. If it is in the list and you have agent-forwarding activated you should have a success. Otherwise you can add the key to your ssh-agent by running ssh-add <path to your key file>.
It sounds like you may be hitting this particular bug:
https://github.com/mitchellh/vagrant/issues/1735
(Despite it being "closed" it's actually not fixed)
On Windows, SSH Forwarding in Vagrant does not work properly by default (because of a bug in net-ssh).
However, there is a workaround or simple hack. You can auto-copy your local SSH key to the Vagrant VM via a simple provisioning script in your VagrantFile. Here's an example:
https://github.com/mitchellh/vagrant/issues/1735#issuecomment-25640783
Tom,
What you're doing is fairly generic in nature and I don't think is Vagrant specific.
Try some of the following to track down the issue:
edit your /etc/ssh/sshd_config
Set LogLevel debug
Restart the sshd service sudo service sshd restart or /etc/init.d/sshd restart
tail -f /var/log/authlog -- note, the file may be something else like /var/log/authd.log or /var/log/secure or something.
Watch what happens when you connect. It should give you some indication of why it's failing.
Again sorry, I'm not that familiar with Vagrant but I'm wondering if the provisioning script is running as another user, in which case the agent forwarding may not work as expected?

Resources