I prefer using the bash terminal to do work, on a Windows system, I would install Git bash to do work.
Recently I have the need to access a windows machine remotely, via SSH. But I find that once I SSH into the windows system I enter into the command prompt. I have tried to activate Git Bash by using:
> "C:\Program Files\Git\git-bash.exe"
But to no avail. How do I access Git-bash via ssh?
Turns out the command I should run is
> "C:\Program Files\Git\bin\sh.exe"
Related
I need to run a shell script on windows that has psql commands. I installed bash and can run the script but the psql commands are failing. So, I installed the PostgreSQL on the windows machine in this location - "C:\Program Files\PostgreSQL\14\scripts\". There is a bat file in here named runpsql.bat that opens a psql shell. I can connect to my database when I run that bat file but how do I get it to do it from the shell script? Currently, my shell script has commands like -
psql -d db -U user etc but those throw a PSQL: Command not recognized error
I want to execute an sh script on a remote Windows 10 computer without logging into interactive shell.
On Linux I would do something like
ssh user#machine "echo execute program automatically && ./my_program "
However when I ssh into my Windows 10 machine using open-ssh server it opens by default cmd. In interactive mode I would now open git-bash
"C:\Program Files\Git\bin\sh.exe" --login
Then execute my script from there.
When I try to combine the commands like this
ssh user#machine ' "C:\Program Files\Git\bin\sh.exe" --login && ./my_program " '
the shell freezes. Without the single quotes, the command also doesn't work (obviously).
So what to do?
Try to change default shell, with administrator CMD :
reg add HKLM\SOFTWARE\OpenSSH /v DefaultShell /d "C:\Program Files\Git\bin\sh.exe"
So I am running a script that calls:
docker-compose run --rm web sh /data/bin/install_test_db.sh
and it seems to work fine when running it on ubuntu but when I run it on Windows using Git Bash I get this error:
sh: 0: Can't open C:/Program Files/Git/data/bin/install_test_db.sh
It seems to be trying to run the script on my machine and not the actual container from which I am trying to call it from.
Any ideas on why this is happening?
First, try passing a command to your sh shell:
docker-compose run --rm web sh -c "/data/bin/install_test_db.sh"
Or:
docker-compose run --rm web "sh -c /data/bin/install_test_db.sh"
That will avoid your host shell (the git bash) to interpret an absolute path (starting with '/') as one from the Git installation path.
That will keep /data/... as an argument to be passed to the shell executed in the container.
Note: If you are using Docker for Windows (meaning not VirtualBox, but HyperV), you don't need git bash at all.
Try the same command from a regular CMD (with docker.exe in your %PATH%, which Docker for Windows set for you)
vonc#VONCAVN7 C:\Users\vonc
> where docker
C:\Program Files\Docker\Docker\Resources\bin\docker.exe
If you need Linux-like commands from that same CMD session, then yes, add git paths:
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
If I vagrant ssh with windows cmd, I get a nice command prompt, like that:
vagrant#homestead:~$ echo foo
vagrant#homestead:~$ foo
But with cygwin and mintty, I have no prompt at all:
echo foo
foo
I see it has to do with "pseudo-tty allocation".
With cygwin and mintty, I can have my prompt with this :
vagrant ssh -- -t -t
How can I change cygwin and mintty so that I don't have to tell the -t ?
About the ssh -t option :
"Force pseudo-tty allocation. This can be used to execute arbi-
trary screen-based programs on a remote machine, which can be
very useful, e.g., when implementing menu services. Multiple -t
options force tty allocation, even if ssh has no local tty."
I had the same problem with and the solution was to set the VAGRANT_PREFER_SYSTEM_BIN environment variable to get vagrant to use your normal ssh executable.
You can do:
VAGRANT_PREFER_SYSTEM_BIN=1 vagrant ssh
or put this into your .bash_profile:
export VAGRANT_PREFER_SYSTEM_BIN=1
Reference: https://github.com/hashicorp/vagrant/issues/9143#issuecomment-343311263
I run in the same problem described above. But only on one of three PCs. But as a workaround I am doing:
# save the config to a file
vagrant ssh-config > vagrant-ssh
# run ssh with the file.
ssh -F vagrant-ssh default
From an answer of How to ssh to vagrant without actually running "vagrant ssh"?
In this case I am getting the prompt and what's more important also history cycling and ctrl-c etc. are working properly.
Vagrant is a windows program managing Virtual machine
https://www.vagrantup.com/intro/index.html
as such it does not well interface with the pseudo tty
structure used by cygwin programs.
Read for reference on similar issues with a lot of other windows program
https://github.com/mintty/mintty/issues/56
Mintty is a Cygwin program. It expect interactive program running inside it to use the cygwin tty functionality for interactive behaviour.
Running Vagrant from Bash in Windows CMD, make CMD the terminal control so Vagrant has no problem in the interactive behaviour.
I do not see the need to run Vagrant inside Cygwin
Since vagrant is windows-based, I use ConEmu instead of cygwin's shell (mintty)
choco install conemu via chocolatey and it works
General solution is to teach vagrant to use ssh, compatible with preferred terminal. Like Cygwin ssh+mintty.
Modern Vagrant (v2.1.2) has VAGRANT_PREFER_SYSTEM_BIN=1 by default on Windows.
To troubleshoot issue:
VAGRANT_LOG=info vagrant ssh
In v2.1.2 they broke Cygwin support. See my bug report with hack to lib/vagrant/util/ssh.rb to make it work.
I executed this command "C:\Program Files (x86)\Git\bin\git.exe" clone ssh://<user>#<org>:<path to repo> in Git bash terminal and in normal command prompt.
When executed in Git Bash terminal, the clone works fine, but while running it in command prompt, it gives following error.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I need to run git clone through windows batch script, that's why
i need to make it run through command line. How to do that work ?
Note :-
1. Add public key to remote(gerrit) that was generated using ssh-keygen.
Your SSH identity is not found while running from command line. Make sure that %HOME%\.ssh directory contains your keys.