SSH via WSL in VSCODE to specific port - visual-studio-code

Referring to this thread Can I ssh from WSL in visual studio code?
I'm able to ssh on port 22 but is there a way to specify a port via WSL also?
my config:
Host IP
HostName IP
ForwardAgent yes
Port 2222
my ssh.bat
C:\Windows\system32\wsl.exe bash -ic 'ssh %*'
however it's not connecting with the following errors
[11:01:27.830] "install" terminal command done
[11:01:27.831] Install terminal quit with output: error: unknown command: bash
[11:01:27.832] Received install output: error: unknown command: bash
[11:01:27.833] Failed to parse remote port from server output
[11:01:27.834] Resolver error: Error:
I see the obvious command: bash error but I have multiple connections using this ssh.bat so reluctant to mess with it.
Any ideas would be helpful thanks!

Related

Issue with REMOTE-SSH into vagrant using VSCode (Mac)

I am trying to follow this link to try connecting into my vagrant vm box with VSCode in Mac Catalina. But every time I am getting "could not establish connection with default".
The link said to copy the 'vagrant ssh-config' results to ~/.ssh/config. Before I did this, the ~/.ssh folder was empty.
The content of the config file copied from 'vagrant ssh-config' is as follows:
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/stewartty/udacity-courses/fullstack/vagrant/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
Host vagrant
HostName vagrant
User vagrant
In VSCode, I installed the Remote-SSH extension. Then I followed exactly to the word as laid out in the link (open command palette and select the ./ssh/config file AND again, open command palette and select 'Remote SSH: Connect to Host... and select 'Default').
Check your vagrant IP.
most of the time has your inet range ip, to see the virtual machine
ifconfig | grep inet
Refer to the Vagrantfile network section
I made a rookie mistake - I should have run vagrant up first before trying to remote-ssh using VSCode. I’ve had no problem remoting after running vagrant up.

connecting vs code to gcp cloudshell via ss

I'm trying to connect vscode to cloud shell through ssh. I found the following article https://medium.com/#alex.burdenko/vs-code-happens-to-be-my-favorite-code-editor-and-ive-been-lucky-to-participate-so-many-diverse-952102856a7a. I followed all the steps and I'm able to ssh via the command line. However when I try to ssh via vscode I get an error.
This is what I have specified in the config file
Host tmp_user#35.186.145.21
Port 6000
ForwardAgent yes
HostName tmp_user#35.186.145.21
User tmp_user
IdentityFile ~/.ssh/google_compute_engine
When I execute gcloud alpha cloud-shell ssh --dry-run I get the following
/user/bin/ssh -t -p 6000 -i /home/tmpus/.ssh/google_compute_engine -o StrictHostKeyChecking=no tmp_user#35.186.145.21 -- DEVSHELL_PROJECT_ID=myprj 'bash -l'
Google's Cloud Code extension for VS Code should automatically connect you to Cloud Shell via SSH. You can use one of the documented links here to automatically install the extension and open a sample or you can install Cloud Code directly from the marketplace and utilize the command palette (ctrl/cmd-shift-p) to run Cloud Code: Open in Cloud Shell.... This will also create the requisite entry in your host file but please keep in mind that IPs, host names, etc are temporary and only valid while the instance of your Cloud Shell session is live. This is likely the reason your connection fails with access is denied.
Remove "tmp_user#" from the HostName field.
Try this:
Host tmp_user#35.186.145.21
Port 6000
ForwardAgent yes
HostName 35.186.145.21
User tmp_user
IdentityFile ~/.ssh/google_compute_engine
When you create cloud shell with
gcloud cloud-shell ssh --authorize-session --dry-run
In the answer you have something like this:
/usr/bin/ssh -t -p 6000 -i /home/tmp_user/.ssh/google_compute_engine -o StrictHostKeyChecking=no tmp_user#35.186.145.21 -- DEVSHELL_PROJECT_ID=XXXXXXXX 'bash -l'
So you add StrictHostKeyChecking parameter (UserKnownHostsFile /dev/null because it's temporary).
Your config file is like this:
Host tmp_user#35.186.145.21
Port 6000
ForwardAgent yes
HostName 35.186.145.21
User tmp_user
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
IdentityFile ~/.ssh/google_compute_engine

WSL-2: Connect from Windows host machine to Ubuntu guest running PostgreSQL

I'm running PostgreSQL 10 on a Windows 10 WSL-2 installation of Ubuntu 18.04. I can start the service, connect to it locally from within Ubuntu with psql, and use it for local development. So far, so good!
I'd like to be able to connect to this instance from the host Windows OS, but can't connect. From Windows cmd, I've tried using telnet to see if I can connect to the NAT IP of the Ubuntu machine:
$ telnet 172.123.456.789 5432
Connecting To 172.31.175.251...Could not open connection to the host, on port 5432: Connect failed
When I run Django's runserver on port 8000, however, I can connect:
$ telnet 172.123.456.789 8000
[connected, returns HTML]
I've tried checking to see if it was something in Ubuntu's firewall ufw, but it isn't running:
$ sudo ufw status verbose
Status: inactive
Has anyone cracked this nut?

i'm getting following error while connecting to mongodb server

$ mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-10-18T17:09:03.003+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-10-18T17:09:03.004+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
what OS are you using? In ubuntu you need to check your version:
service mongod status, mongod --version.
If mongod is off then just restart and write the error if possible.
service mongod restart
if you are using linux, try this command
$ sudo mongod
you are getting that because you are running
$ mongo
First go to your mongoDB directory and in that directory go to bin directory and open terminal in that directory(bin), then run the following command:
mongod.exe
After that open another terminal in same directory and run the following command.
mongo.exe
It will resolve this issue.
first you check it mongodb proper installed or not and also check it version compatibility
I am saying windows os setup,
set environment variable is path C:\Program Files\MongoDB\Server\3.6\bin;
then open your command prompt and type
mongod
after open another command prompt and type
mongo
A connection refused failure to connect reason may just be a matter of your network configuration and firewall or more specifically, your operating system's port restrictions. While you may be connecting to a mongoDB server on localhost (127.0.0.1) which can't be blocked by a firewall, it is possible for a firewall to block access to specific ports on a localhost.
If you're on a linux-based system, this can be addressed by using iptables as described here with the applicable commands shown below:
iptables -A INPUT -s 127.0.0.1 -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -d 127.0.0.1 -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
However, in reading the comments on another answer, it may be that you aren't able to connect because the server isn't being launched and ran properly due to a lack of of the /data/db directory. But, a presumption based on the lack of reply to other answers suggesting to check your server is running properly, tells me you're sure that it is. In which case, try changing your hostname to localhost instead of 127.0.0.1 when connecting, as in:
mongoose.connect('mongodb://localhost:27017');
# or as more applicable for connecting to a deployment:
mongosh "mongodb://localhost:27017"
# alternatively, by default, MongoDB Shell already connects to localhost
# so you could simply use the command line option --port such as:
mongosh --port 27017
You can also try specifying more parameters in the url as it applies.
For example, connecting to an instance and authenticate against the foobar database as user rohan:
mongosh "mongodb://localhost:27017" --username rohan --authenticationDatabase foobar
To provide a password with the command instead of using the masked prompt, simply add the --password command line option.
For Windows, you may also try the solutions offered on this page.

Error Connecting to PostgreSQL on Red Hat Openshift gear

Permit my noobishness, I'm learning how to work with Linux Openshift. While following a book, I tried to connect to the server online from the command line [Bash]. I ran
rhc port-forward
and it displayed:
Checking available ports ... done
Forwarding ports ...
To connect to a service running on OpenShift, use the Local address
Service Local OpenShift
---------- -------------- ---- ---------------
httpd 127.0.0.1:8080 => 127.7.74.1:8080
postgresql 127.0.0.1:5432 => 127.7.74.2:5432
Press CTRL-C to terminate port forwarding
The book said I should run
psql -h 127.0.0.1 -p 5433 -U username password
Now why does bash complain anytime I run the command,
psql -h 127.0.0.1 ...
It says, psql command not found.
check and make sure that you have psql installed on your local machine. If not use a package manager like yum (fedora/RHEL) or Brew (Mac) to install the necessary binaries to get the psql command.
The problem was that my internet connection breaks off at some point while I am cloning to my local machine. Thank you all for you contribution. It needs a strong internet connection and it takes quite a time to clone: https://github.com/postgres/postgres.git.