Last active
April 6, 2025 18:18
-
-
Save Be1zebub/024acb15e16e2c7231ab484c97a717ce to your computer and use it in GitHub Desktop.
Run ssh sessions in winscp with openssh + windows terminal (ssh key auth only)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM winscp + wt + openssh | |
REM Run ssh sessions in winscp with openssh + windows terminal (ssh key auth only) | |
REM https://gist.github.com/Be1zebub/024acb15e16e2c7231ab484c97a717ce/ | |
REM 1. replace %ProgramFiles%\PuTTY\putty.exe in WinSCP settings (integrations > software > terminal path) | |
REM with "cmd.exe /c C:/winscp_wt_ssh.bat !@ !# !U !/ !N" | |
REM 2. add your ssh key to ssh-agent (ssh-add %UserProfile%/.ssh/myShhKey) | |
REM if ssh-agent not running - use "Set-Service -Name ssh-agent -StartupType Automatic" & "Start-Service ssh-agent" | |
REM Wanna customize wt tab? create "ssh-winscp" profile for it | |
REM list of params that WinSCP sends to this batch script | |
REM wanna make sure its all good? add 6rd arg "debug" to this script launch params | |
REM 1. !@ - is hostname | |
set WINSCP_SSH_HOST=%1 | |
REM 2. !# - is port | |
set WINSCP_SSH_PORT=%2 | |
REM 3. !U - is username | |
set WINSCP_SSH_USER=%3 | |
REM 4. !/ - is path | |
set WINSCP_SSH_PATH=%4 | |
REM 5. !N - is connection name | |
set WINSCP_SSH_NAME=%5 | |
REM 6. debug - if the 6th parameter is "debug", print debug info | |
if "%6"=="debug" ( | |
echo Debug mode activated. | |
echo All params: %* | |
echo. | |
echo 1. ^!@ ^(hostname^) - "%WINSCP_SSH_HOST%" | |
echo 2. ^!# ^(port^) - "%WINSCP_SSH_PORT%" | |
echo 3. ^!U ^(username^) - "%WINSCP_SSH_USER%" | |
echo 4. ^!/ ^(path^) - "%WINSCP_SSH_PATH%" | |
echo 5. ^!N ^(connection name^) - "%WINSCP_SSH_NAME%" | |
echo. | |
PAUSE | |
exit /b | |
) | |
start wt.exe -w 0 new-tab ^ | |
--tabColor "#003b33" ^ | |
--profile "ssh-winscp" ^ | |
--title "%WINSCP_SSH_NAME%" ^ | |
--suppressApplicationTitle ^ | |
ssh %WINSCP_SSH_USER%@%WINSCP_SSH_HOST% -p %WINSCP_SSH_PORT% -o ServerAliveInterval=60 -t "cd \"%WINSCP_SSH_PATH%\" \; bash --login" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment