I want to use my cygwin configuration for SSH ou SFTP connection but doesn't work.
My configucation file "config" is in directory C:\cygwin64\home\<username>\.ssh. This configuration file define an SSH proxy jump and send some environment variables. This configuration file work fine in cygwin to connect in SSH or SFTP.
In PhpStorm settings I've specified the shell path in Tools > Terminal to be C:\cygwin64\bin\bash.exe --login -i. All local terminal use cygwin fine. But the ssh connection don't use my configuration file. I tried copying configuration in C:\Users\<username>\.ssh directory but that does not work.
Can you help me?
Generally, creating %USERPROFILE%/.ssh/config file pointing to the actual location of keys (using a valid Windows path) should help. But PhpStorm does not support ProxyJump and ProxyCommand instructions in it because there is no support for it from OpenSSH client's Windows port and we cannot use Cygwin or MinGW OpenSSH clients, which support proxying, but require running in theirs own shell subsystem. Here's a related bug report: https://youtrack.jetbrains.com/issue/IDEA-214679
I found the solution. You need to install the latest version of OpenSSH. To achieve this, I did the following actions:
Installing the scoop package manager (https://scoop.sh/) using PowerShell
$ Set-ExecutionPolicy RemoteSigned -scope CurrentUser Answer Y
$ Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
Installing OpenSSH
$ scoop install win32-openssh
normally the installation modifies the environment variable %PATH% to add the path something like C:\Users\<username>\scoop\shims. Otherwise you have to add it.
Modification of the environment variable %PATH% to remove the path C:\Windows\System32\OpenSSH
Enable the "OpenSSH Authentication Agent" service
On keyboard press Windows + R
Type: services.msc and press Enter.
Double click on the "OpenSSH Authentication Agent" service
Select the "Automatic" start type and start the service.
After these actions, I was able to connect from the Windows cmd terminal. I tested from PhpStorm and it works too.
Related
I have tried to connect to a server using ssh but I got the following error ssh :
The term 'ssh' is not recognized as the name of a cmdlet, function, script file, or operable program.
I have followed the tutorial from https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse#:~:text=Install%20OpenSSH%20using%20PowerShell.%20To%20install%20OpenSSH%20using,the%20following%20output%20if%20neither%20are%20already%20installed%3A
and managed to install OpenSSH.client and server but I get the same error when trying to run ssh.
I am running on Windows 10 Pro.
I have tried uninstalling OpenSSH and reinstalling it back, restarting the computer but nothing changed.
EDIT :
In a strange way, ssh started working the very next day. I guess the solution was to restart the computer after uninstalling and reinstalling ssh back.
Try first the same command in a new Powershell Windows, one which will inherit from the system changes you just did by installing OpenSSH for Windows
Make sure you do see a C:\Windows\System32\openssh\ssh.exe.
As mentioned in "OpenSSH Server Configuration for Windows 10"
First confirm that the OpenSSH installation folder is on the system path.
For Windows, the default installation folder is SystemDrive:WindowsDirectory\System32\openssh.
In my case, OpenSSH was installed properly and the folder structure was also ok.
However, the ssh syntax was not accepted. So, the solution was just to execute the ssh.exe as:
PS C:\WINDOWS\system32\openssh> .\ssh
I've been trying to get access to Windows Server 2019 without password through OpenSSH protocol.
So I've created new key which I need it to be copied to the Windows Server, I've tried this:
ssh-copy-id -i ~/.ssh/id_rsa user#server
But I get this after entering correct password:
'exec' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the path specified.
The system cannot find the path specified.
My issue is how to transfer key from one windows machine(using gitbash, WSL, powershell or whatever)
to Windows Server 2019 location of authorized keys if I am not mistaken.
I am desperate enough to do it manually but location of those keys is mystery to me, do I need to set something on Windows Server first so that it can accept keys for authentication ?
What is the alternative on ssh-copy-id from Windows machine to Windows Server 2019 ?
Found solution:
Followed this helpful youtube guide, props to the
https://www.youtube.com/watch?v=Cs3wBl_mMH0&ab_channel=IT%2FOpsTalk-Deprecated-SeeChannelDescription
Also, installing OpenSSHUtils worked with:
Install-Module -Name OpenSSHUtils -RequiredVersion 0.0.2.0 -Scope AllUsers
Also this guide helped:
https://www.cloudsma.com/2018/03/installing-powershell-modules-on/
My server didn't have access so I manually copied file from:
C:\Program Files\WindowsPowerShell\Modules to the server's:
Server:\Program Files\WindowsPowerShell\Modules
First, this error message is followed by microsoft/vscode-remote-release issue 25
Current workaround (the context is VSCode, but should apply also for regular SSH connection):
Also, for anyone else here that loves their bash on windows but still wants to be able to use VSCode remote, the workaround I have currently setup is to use an autorun.cmd deployed on the servers that detects when an SSH connection is coming in and has a terminal allocated:
#echo off
if defined SSH_CLIENT (
:: check if we've got a terminal hooked up; if not, don't run bash.exe
C:\cygwin\bin\bash.exe -c "if [ -t 1 ]; then exit 1; fi"
if errorlevel 1 (
C:\cygwin\bin\bash.exe --login
exit
)
)
This is known to work with Cygwin bash, unsure about bash that ships with windows; I imagine it's very sensitive to how the TTY code works internally.
This way, launching cmd.exe works normally, using VSCode (because it does not allocate a PTY) works normally, but SSH'ing into the machine launches bash.exe.
I suspect it would also work using the bash.exe which comes with Git for Windows, should it be installed on the target server.
The destination file should be on the server:
%USERPROFILE%\.ssh\authorized_keys
If you can do it manually, simply try and scp it instead of using ssh-copy-id
scp user#server:C:/Users/<user>/.ssh/authorized_key authorized_key
# manual and local edit to add the public key
scp authorized_key user#server:C:/Users/<user>/.ssh/authorized_key
(again, I would use the scp.exe coming with Git For Windows, installed this time locally)
Found solution:
Followed this helpful youtube guide, props to the
https://www.youtube.com/watch?v=Cs3wBl_mMH0&ab_channel=IT%2FOpsTalk-Deprecated-SeeChannelDescription
Also, installing OpenSSHUtils worked with:
Install-Module -Name OpenSSHUtils -RequiredVersion 0.0.2.0 -Scope AllUsers
Also this guide helped:
https://www.cloudsma.com/2018/03/installing-powershell-modules-on/
My server didn't have access so I manually copied file from:
C:\Program Files\WindowsPowerShell\Modules to the server's:
Server:\Program Files\WindowsPowerShell\Modules
I assume I messed up something since nobody has a similar question here. When I SSH into a windows laptop it does not give me the UNIX shell by default, instead it lands me directly at the Windows prompt. I then have to enter bash, followed by cd and then I can run the commands I need.
Is this a windows setting problem or an openssh issue and does anyone have any suggestions on how I can avoid needing to enter these commands every time that I log in?
The Windows SSH daemon is openssh, and by default it is setup to use cmd as the shell, but you can edit the configuration to use powershell, bash, or any other third party shell. Follow the information in this link.
Its given in MS PoweShell documentation should go through.
To set the default command shell, first confirm that the OpenSSH installation folder is on the system path. For Windows, the default installation folder is SystemDrive:WindowsDirectory\System32\openssh.
Configuring the default ssh shell is done in the Windows registry by adding the full path to the shell executable to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH in the string value DefaultShell.
Here is the example, the following Powershell command sets the default shell to be PowerShell.exe:
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
For further explanation refre this link.
I first installed a Ubuntu linux subsystem with the windows store.
I then installed the hyper terminal for windows like explained in this tutorial : https://medium.com/#ssharizal/hyper-js-oh-my-zsh-as-ubuntu-on-windows-wsl-terminal-8bf577cdbd97
Like it is written in the tutorial I put C:\\Windows\\System32\\bash.exe in the hyper configuration file.
However, afterwards, I installed another linux subsystem, Wlinux.
So now I have two subsytems located here
Wlinux : C:\Users\martinpc\AppData\Local\Packages\WhitewaterFoundryLtd.Co....
Ubuntu : C:\Users\martinpc\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_7...
However, when I open the hyper terminal, It seem like I can only access the files of the ubuntu distrib and not the Wlinux. Therefore, I would like to know how I can point Hyper to Wlinux and not Ubuntu anymore. Thank you for your answer.
First of all, bash.exe has been deprecated. You should use wsl.exe in command lines. Check your installed distributions in WSL with wslconfig.exe /list /all command. Alternatively, for Windows 10 version 1903 and above, wsl.exe --list --all command can be used. Choose the distribution that you want to connect with HyperJS Terminal emulator. Open up Hyper.js configuration with Ctrl + , or open %UserProfile%\.hyper.js in any text editor. Edit the shell configuration from these two named values:
shell: 'C:\\Windows\\System32\\wsl.exe',
shellArgs: ['--distribution', 'Your-Distro-Name'],
Alternatively, you can use wslconfig.exe /setdefault <DistributionName> command to change default distribution. With this step, you can skip the shellArgs line in .hyper.js configuration file.
The Question
I'm trying to enable X11 forwarding through the PyCharm SSH Terminal which can be executed via
"Tools -> Start SSH session..."
Unfortunately, It seems there is no way of specifying the flags like I would do in my shell for enabling the X11 Forwarding:
ssh -X user#remotehost
Do you know some clever way of achieving this?
Current dirty solution
The only dirty hack I found is to open an external ssh connection with X11 forwarding and than manually update the environment variable DISPLAY.
For example I can run on my external ssh session:
vincenzo#remotehost:$ echo $DISPLAY
localhost:10.0
And than set on my PyCharm terminal:
export DISPLAY=localhost:10.0
or update the DISPLAY variable in the Run/Debug Configuration, if I want to run the program from the GUI.
However, I really don't like this solution of using an external ssh terminal and manually update the DISPLAY variable and I'm sure there's a better way of achieving this!
Any help would be much appreciated.
P.s. Making an alias like:
alias ssh='ssh -X'
in my .bashrc doesn't force PyCharm to enable X11 forwarding.
So I was able to patch up jsch and test this out and it worked great.
Using X11 forwarding
You will need to do the following to use X11 forwarding in PyCharm:
- Install an X Server if you don't already have one. On Windows this might be the VcXsrv project, on Mac OS X the XQuartz project.
- Download or compile the jsch package. See instructions for compilation below.
- Backup jsch-0.1.54.jar in your pycharm's lib folder and replace it with the patched version. Start Pycharm with a remote environment and make sure to remove any instances of the DISPLAY environment variable you might have set in the run/debug configuration.
Compilation
Here is what you need to do on a Mac OS or Linux system with Maven installed.
wget http://sourceforge.net/projects/jsch/files/jsch/0.1.54/jsch-0.1.54.zip/download
unzip download
cd jsch-0.1.54
sed -e 's|x11_forwarding=false|x11_forwarding=true|g' -e 's|xforwading=false|xforwading=true|g' -i src/main/java/com/jcraft/jsch/*.java
sed -e 's|<version>0.1.53</version>|<version>0.1.54</version>|g' -i pom.xml
mvn clean package
This will create jsch-0.1.54.jar in target folder.
Update 2020:
I found a very easy solution. It may be due to the updated PyCharm version (2020.1).
Ensure that X11Forwarding is enabled on server: In /etc/ssh/sshd_config set
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
On client (MacOS for me): In ~/.ssh/config set
ForwardX11 yes
In PyCharm deselect Include system environment variables. This resolves the issue that the DISPLAY variable gets set to the system variable.
EDIT: As seen in the below image it works. For example I used the PyTorch implementation of DeepLab and visualize sample images from PASCAL VOC:
X11 forwarding was implemented in 2021.1 for all IntelliJ-based IDEs. If it still doesn't work, please consider creating a new issue at youtrack.jetbrains.com.
By the way, the piece of advice about patching jsch won't work for any IDE newer than 2019.1.
In parallel, open MobaXTerm and connect while X11 forwarding checkbox is enabled. Now PyCharm will forward the display through MobaXTerm X11 server.
This until PyCharm add this 'simple' feature.
Also, set DISPLAY environment variable in PyCharm run configuration like this:
DISPLAY=localhost:10.0
(the right hand side should be obtained with the command echo $DISPLAY in the server side)
Update 2022: for PyCharm newer than 2022.1: Plotting in SciView works by only setting ForwardX11 yes in .ssh/config (my laptop OS is ubuntu 22.04). I did not set any other parameters either on the server or local side.