Adding -c flag to ssh remote host with visual studio code - windows

Simply, I am unable to mimic a ssh -c <cipher> <user>#<host> call with Remote SSH with VS Code. I allow the extension (Remote SSH) to auto-generate the config based off the input ssh command, yet the command is not replicated when the config file is sourced
The command output in VS Code's terminal
[Timestamp] Running script with connection command: ssh -T -D <5 digit Port> -F "<Path to Config File>" "<Host>" bash
The provided ssh command
ssh <user>#<host> -c <cipher>
And the auto-generated config contents inside VS Code
Host <hostname>
HostName <hostname>
User <user>
Cipher <cipher>
Any guesses on why the disconnect between the provided command, the generated config file and the output command? I am unable to find anything online with VS Code & SSH & Usage of Ciphers.
If important, this is from Windows 10 to a Linux box on an AWS workspace virtual machine, and I can ssh no problem from powershell as well as use remote interpeter within pycharm professional on the windows machine

Related

SSH and SCP failed with "CreateProcessW failed error:2 posix_spawn: No such file or directory"

I am trying to do SSH and SCP to AWS managed instance. The public key of my machine is stored at that managed instance. There is no .pem file required. I am using the following commands.
scp -r username#instance-id:/pathtoremotefile localpath
scp localfilepath username#instance-id:~
ssh username#instance-id
But none of these are working in windows.The error says,"CreateProcessW failed error:2 posix_spawn: No such file or directory lost connection". I would mention that I am able to start ssm session to that instance using this command
aws ssm start-session --target instance-id.
Managed instance has linux operating system and my pc has windows.
Also, in config file of .ssh directory, I've added following lines.
host i-* mi-*
ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
The strange thing is I am able to do both ssh and SCP in 'windows subsystem from Linux' from the same machine by using the same commands. But couldn't do that in windows command prompt.
What am I doing wrong?
This seems to be a problem of the Windows openSSH package.
In ProxyCommands it requests full path qualifiers, but better use forward slashes there!
ProxyCommand C:/somepath/sh.exe -c "aws ssm ...
I don't use the windows openSSH anymore, instead I'm using the ssh command from git-bash to avoid all the windows problems.
The key agent works perfect, proxyCommand/proxyJumps works, and in contrast to windows, it's reliable.

Powershell to connect to a remote linux ssh server and executing a command line

I have to connect from a Windows 10 / Windows Server 2016 machine to a Linux machine (CentOS) to execute a command to disable a server in haproxy. On a local Linux machine the command is sudo echo "disable server http/test1" | socat tcp:127.0.0.1:9191 stdio and it works. But I have to create a script / command line to let a Windows machine do the magic. I´ve tried powercat but it will not work. So I decide to use ssh client on the Windows machine. The command line is
ssh -l haproxy-user -i private.ppk 10.0.0.20 "sudo echo "disable server http/test1" | socat tcp:127.0.0.1:9191 stdio" but I didn´t get the option to enter the passphrase for my identy file. Or is there another option to execute the command line?

SSH to remote Windows machine using username and password through shell script

I am trying to SSH to a remote Windows machine (an AWS ec2 instance) by using an username and password of the remote machine. I need to automate this connection to run some remote commands from my script (either shell or Power shell) without prompting me for a password, My script shouldn't fail by expecting a password to be prompted
I don't want to use sshpass or any generated keys (by using ssh-keygen). Since the source machine where I run this command/script is not a dedicated machine, I may run it on a different machine everytime. I also gave a try to connect using the .PEM file provided by AWS as below (thought it could be easy while using it the script).
$ssh -i aws_keypair.pem Administrator#10.10.10.10
Administrator#10.10.10.10's password:
It is still expecting me for a password even if I used the .PEM file, I also tried to created an file 'authorized_keys' in the remote Windows machine under the path "C:\Users\Administrator.ssh\". Still it is prompting me for a password.
Expectation :
Connect to remote Windows machine using PEM file and run some remote commands.
(or)
It shouldn't prompt me for a password while I try for the connection from some script (shell/power shell).
Can be done without any 3rd party tools like this:
$env:TMPPW=Get-Content -Path 'secure_file.txt' ; $un='MyUserName'
$j=Start-Job -ScriptBlock{Start-Sleep -Seconds 1
(New-Object -ComObject wscript.shell).SendKeys("$env:TMPPW{ENTER}")}
& ssh.exe -q -4 -l $un 127.0.0.1 'whoami'
$env:TMPPW=([guid]::NewGuid()).Guid ; $env:TMPPW=$null
I am able to achieve this using Plink command (Installation of Putty is required on source machine to execute this command). So now, I am able to successfully pass the username and password with in the script (Shell script) and everything is working as expected.
FYI, I am pasting the exact command which worked for me
$echo y | plink -ssh Administrator#10.10.10.10 -pw abc123 "dir"

Is there a way to make rsync execute a command before beginning its transfer

I am working on a script which will be used to transfer a file (using rsync) from a remote location and then perform some basic operations on the retrieved content.
When I initially connect to the remote location (not running an rsync daemon, I'm just using rsync to retrieve the files) I am placed in a non-standard shell. In order to enter the bash shell I need to enter "run util bash". Is there a way to execute "run util bash" before rsync begins to transfer the files over?
I am open to other suggestions if there is a way to do this using scp/ftp instead of rsync.
One way is to exectue rsync from the server, instead of from the client. An ssh reverse tunnel allows us to temporarily access the local machine from the remote server.
Assume the local machine has an ssh server on port 22
Shh into the remote host while specifying a reverse tunnel that maps a port in the remote machine (in this example let us use 2222) to port 22 in our local machine
Execute your rsync command, replacing any reference to your local machine with the reverse ssh tunnel address: my-local-user#localhost
Add a port option to rsync's ssh to have it use the 2222 port.
The command:
ssh -R 2222:localhost:22 remoteuser#remotemachine << EOF
# we are on the remote server.
# we can ssh back into the box running the ssh client via ${REMOTE_PORT}
run utils bash
rsync -e "ssh -p 2222" --args /path/to/remote/source remoteuser#localhost:/path/to/local/machine/dest
EOF
Reference to pass complicated commands to ssh:
What is the cleanest way to ssh and run multiple commands in Bash?
You can achieve it using --rsync-path also. E.g rsync --rsync-path="run util bash && rsync" -e "ssh -T -c aes128-ctr -o Compression=no -x" ./tmp root#example.com:~
--rsync-path is normally used to specify what program is to be run on the remote machine to start-up rsync. Often used when rsync is not in the default remote-shell’s path (e.g. –rsync-path=/usr/local/bin/rsync). Note that PROGRAM is run with the help of a shell, so it can be any program, script, or command sequence you’d care to run, so long as it does not corrupt the standard-in & standard-out that rsync is using to communicate.
For more details refer

Transfer a file to remote machine(ubuntu) while running bash remotely

I have written a bash script which I should run on the remote server(ubuntu) with GUI(zenity) interface and I will issue below command on the local machine.
sshpass -p $PASS ssh root#$SERVER 'bash' < /tmp/dep.sh | tee >(zenity --progress --title "Tomcat Deployer" --text "Connecting to Tomcat Server..." --width=400 --height=150) >>/tmp/temp.log;
I want to transfer a file from my local machine to server and I want to achieve this placing an enter in bash file(/tmp/dep.sh) in the above command itself without opening a new session on server.
I prefer below command to transfer the file to server and I should place this in the bash script(/tmp/dep.sh) and it should run on server to copy the file from my local machine. I don't want to specify my local ip as a variable and use as source in the blow command as the script is used on other machines too and thus ip changes. And I should not transfer the file from my local to server writing a separate rsync & ssh creating one more ssh session.
rsync --rsh="sshpass -p '$PASS' ssh" '$local:$APPATH/$app.war' /tmp
Anybody can do any magic to transfer the file from local to server with the above connected ssh session with the help of above rsync or by other means and without opening new separate connection?
Thank you!
Edit 1:
Could this be achieved with single ssh session(single command)?:
rsync --rsh="sshpass -p serverpass ssh -o StrictHostKeyChecking=no" /home/user1/Desktop/app.war root#192.168.1.5:/tmp;
sshpass -p serverpass ssh -o StrictHostKeyChecking=no root#192.168.1.5 '/etc/init.d/tomcat start'
You'll want to use SSH multiplexing. This is done using the ControlMaster and ControlPath options. Here's an article on it.

Resources