login via ssh using ssh.net (renci) to an external device always throws invalid command [duplicate] - ssh.net

This question already has an answer here:
SSH.NET is not executing command on device
(1 answer)
Closed 1 year ago.
I would like to create an application to send SSH commands to HP Switches and some other devices. But from HP Switch I get response "SSH command execution is not supported.".
I use this part of a code.
SshClient sshclient = new SshClient(IP,username, pass);
sshclient.Connect();
SshCommand sc = sshclient.CreateCommand("conf");
sc.Execute();
string answer = sc.Result;
label9.Text = answer;
Any ideas how to make the interactive shell emulation?
I found only this thread regarding to this issue.
phpseclib - attempting to connect to an HP procurve switch returns error: SSH command execution is not supported

Your code is correct in general. But it seems, that the particular device does not support the SSH "exec" channel, what is behind the SshCommand class.
As the answer to the question you have linked yourself suggests, you have to unfortunately emulate a shell by using SSH "shell" channel.
For that use SshClient.CreateShell and write the command to its input stream.
Note that this is just a workaround for your specific situation. In general, the "shell" channel shall not be used for automation.

Related

How to automate OPENVPN login [duplicate]

This question already has answers here:
Send string to stdin
(6 answers)
Closed 2 years ago.
I created a very simple bash script. The first line of the script after #!/bin/bash accesses my vpn service using an OPENVPN file provided by the VPN Vendor. It works as expected and then waits for data entry of my username and once entered expects my password.
I used the echo command to provide the required responses but they never occur. Open VPN just sits there waiting for my username. If I hit enter twice then OPENVPN terminates and my script completes by echoing the username and password.
#!/bin/bash
sudo openvpn /etc/openvpn/us-dtw.prod.xxxxxxx.com_udp.ovpn
echo $'\r'
printf " xf3Z3ZY6xxxxxxxxEuRDmh"
echo $'\r'
echo " nvn7B5kxxxxhxxJstRU"
What could be causing my script to hang and not execute the echo commands until OPENVPN terminates?
Maybe there is a way to pipe the text but I am really new to this.
Found an example that works correctly to automate the VPN logon process: https://help.anonine.com/support/solutions/articles/5000613671-how-do-i-save-my-username-password-in-openvpn-for-automatic-login-
openvpn will by default be using the TTY to get input, not standard input.
Have you looked at the --askpass option to openvpn?

Windows cmd simulate console input a command

I need to write a batch script which connects to a vpn automatically when username and password is saved somewhere (Ex: in a file). VPN client is openconnect which provides a CLI but the problem is user input needs to be provided interactively to the command in order for it to complete.
See the output below when I run :
openconnect <serverhostname>
OUTPUT
POST https://<serverhostname>/
Connected to <serverhostname>:443
SSL negotiation with <serverhostname>
Server certificate verify failed: signer not found
Certificate from VPN server "<serverhostname>" failed verification.
Reason: signer not found
To trust this server in future, perhaps add this to your command line:
--servercert pin-sha256:<somesha>
Enter 'yes' to accept, 'no' to abort; anything else to view:
So I basically have to type yes manually and press Enter (it also prompts for further input), this needs to be automated in a script. Also, it's worth noting that the output is suggesting to provide --server-cert option and I could do that but when it asks the password, there's no option for it.
I tried putting the input lines in a file and redirecting that to the stdin of the command (which did not work but same the method worked on zsh on linux)
openconnect <serverhostname> < inputfile.txt
I also tried piping to stdin of the command which also didn't work.
I think the particular command doesn't read from stdin but directly from the console somehow which I really don't know how, but I could find a bit of information about something called "CON" on cmd.
Any solution is highly appreciated.

How to use gitlab-shell?

I can't seem to find any information or examples about how to use gitlab-shell. My initial approach was simply to attempt an SSH session from my development box to the server. I received an error response like the one from this post:
jacob#mypc: ssh git#git.example.com:
PTY allocation request failed on channel 0
Welcome to GitLab, jacob!
Connection to git.example.com closed.
The error was alleviated by adding the -T parameter like this user does:
jacob#mypc: ssh git#git.example.com:
Welcome to GitLab, jacob!
However, as would be expected with the -T parameter, I am not presented with a shell. At this point I'm not sure what to do. How is gitlab-shell supposed to be used?

Execute multiple commands via SSH and PowerShell

I successfully managed to connect to a Cisco IE-2000-L switch via SSH. I used the Renci SSH.NET library.
Starting guide: http://vwiki.co.uk/SSH_Client_(PowerShell)
My working code is
# Load SSH library (for .NET 4.0 and PowerShell 3)
$DllPath = "D:\temp\Renci.SshNet.dll"
[void][reflection.assembly]::LoadFrom( (Resolve-Path $DllPath) )
# Connect to switch (Cisco IE2000-L) with IP, port, username, password
$SshClient = New-Object Renci.SshNet.SshClient('172.20.91.30', 22, 'admin', 'mypassword')
$SshClient.Connect()
# execute one command on Cisco switch
$SshCommand = $SshClient.RunCommand('show arp')
# show result
$SshCommand.Result
# close SSH connection
$SshCommand.Dispose()
$SshClient.Disconnect()
$SshClient.Dispose()
My problem is
The above code sends just one command. But I want to execute several commands consecutively without closing and reopening a session.
If I add a second command right after the first one
# execute one command on Cisco switch
$SshCommand = $SshClient.RunCommand('show arp')
$SshCommand = $SshClient.RunCommand('show start')
...the script hangs and never finishes. What am I doing wrong?
Minor relevant information
My main goal is to send multiple commands at once to a Cisco switch
I already tried Plink together with batch cmd input. It's not reliable enough. It works sometimes and sometimes not.
I already tried telnet scripting. Too awkward.

How to enter a password into another process prompt from Ruby

I am writing an application that needs to run command on a remote Raspberry PI using a revssh script. revssh is a custom script that implements to some level the Revssh protocol concepts. it uses ssh reverse tunneling to send commands from the server to the clients.
I am using Ruby 2.1, I tried to do this using IO.popen but it does not work, so I tried the following:
# revssh (short for reverse ssh ) enables the execution of remote commands
# from the server on connected clients, like the 'psu_pi_analytics' here. but it requires
# to enter a root password each time you want to run a command using 'revssh -c'
IO.popen('revssh -c psu_pi_analytics uname -a', 'w+') do|io|
io.puts 'password' # enter the password when prompted
puts io.gets
end
this code work if the command to execute run on the local machine, but not in my case.
So any thoughts, or suggestions.
What important here is how to deal with the new connection created by the revssh script using ssh, which is managed in the terminal if the script is run directly from the terminal.
Edit:
By not work I mean it still prompts for the password, even if I puts the password to the io.
You can use an Expect-like library (e.g. RExpect, Expect4r) for interacting with other processes.
Another question related to this: Is there an Expect equivalent gem for Ruby?

Resources