How to send control commands using python's Paramiko library - ssh

I need to SSH a remote machine and get onto the developer mode. To be specific, I want to execute the command 'Ctrl+gog' upon which I will be prompted for a password. I know how to execute the normal commands, for example chan.send("enable\n"). Please provide me with an answer.

chan.send("\x07\x0F\x07")
Above command worked fine for me.Just concatenate the Hexa equivalent for Ctrl-g,Ctrl-o,Ctrl-g which is, x07x0Fx07.

Related

How to automate processes done through screen /dev/ttyUSB0 using paramiko

I have some devices being managed via an RPi. I'm able to SSH to the RPi using PuTTY and send custom commands to those devices but to do so I need to go through screen /dev/ttyUSB0 115200. I would like to automate this process with a Python script using paramiko.
So far I've succeeded in establishing a connection to the host in the usual way:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, 22, username, pw)
The problem comes in with the commands that I would normally issue via screen. Trying to use ssh.exec_command('screen /dev/ttyUSB0 115200', get_pty=True) followed by something like ssh.exec_command('my command') doesn't work and returns a bash command not recognized error. I've since tried to use a channel, using the following format:
chan = ssh.invoke_shell()
chan.settimeout(3)
chan.send('screen /dev/ttyUSB0 115200\n')
time.sleep(1)
chan.send('my command')
time.sleep(1)
if chan.recv_ready():
print(chan.recv(9999).decode('ascii'))
In PuTTY, sending the command would return a series of strings in the terminal. My goal is to capture those strings and print them through Python. When I use the channel approach I don't receive any notice of unrecognized commands, however the received data is limited to my input commands (expected) and some ANSI escape codes. The data I'm looking for does not get returned.
I'm a complete noob when it comes to networking and Linux so I've been feeling my way through the darkness with this. Based on the data I am receiving from the channel, I suspect I'm not connecting to the CLI in the same way I do using a screen in PuTTY. How might I go about doing this or sidestepping the screen entirely?

How to input password on command prompt using VBA?

I've created a procedure on VBA (Excel) that restarts services on remote servers calling the command prompt and executing the "runas" command. I need to enter the command on the servers as administrator. So far it works fine but I don't want to have to type my password for each I want to run the command in. I know how I can automate the task using VBA and the Excel. What I don't know is how could I input my password on the command prompt using VBA?
Can anybody help me?
Thanks.
I've had all sorts of issues trying to convince runas to let me specify passwords from a program.
In the end, I tossed it and downloaded psexec from the Microsoft Windows Sysinternals site, which has other good stuff as well.
While many see this as a tool running remote programs, it can also be used quite happily to run local stuff under a different user name while allowing you to specify the password as a command-line argument, such as:
psexec -d -u USER -p PWD -w WORKDIR EXECUTABLE
You should be able to create a textbox control in VBA with the input mask set to password, this will allow you to enter the password in a non-viewable fashion.
Then you can just construct the psexec command and execute it from VBA, without having to worry about injecting the password into the process running runas.

why ssh-copy-id still need password when using fabric

I have set env.user and env.password,but when I use:
run('ssh-copy-id -i $HOME/.ssh/id_rsa.pub server1')
it still asks me for the password,why?
env.user and env.password are used to ssh to remote server and then run the command inside run () at the remote server.
They are not used for the remote command itself (running in the remote server).
So ssh-copy-id doesn't know anything about the user or password.
If this is not what you mean, I would advice you to edit the question and make things more clear, like providing more context of what you are trying to accomplish: pasting the function that contains this 'run' for example.

Remotely control a graphical vb.net program through a command prompt

I have created a VB.NET program using windows forms. The program runs on a remote PC and displays information on a screen. The computer does not even have a mouse or keyboard connected to it. The program shows the information based on the file that is loaded.
I want to be able to change this file remotely to another file that is already on the remote PC. I can't use a graphical remote desktop client as we have very limited bandwidth.
So, my idea is to change the file using the command prompt (I think I'll need something like SSH). I'm not sure how to do this. Should I use something like this and load DosModule first:
Module DOSModule
Public Sub Main()
Console.Write("First, start with Command Prompt processing ...")
Dim myWinForm As New WinForm
Application.Run(myWinForm)
End Sub
End Module
How would I then read commands that is send to the program? I also only want one instance of the program running.
Thanks
You have 2 options. The first is a custom program that WILL require some network programming, like it or not. I would suggest creating either a Command-Line batch file or else a PowerShell script, then creating a program to transfer the script to the remote computer and execute the script.
The second option and the one better suited for you would be to download an SSH server. An SSH server will essentially open a command window and pipe the input and output over to a telnet client running on your machine. If you are running a version of Windows Server, an SSH server comes with Windows Server. Otherwise, you can download one for free here: http://www.freesshd.com/
Once you install the SSH server, you simply use telnet, from a command prompt, to link up with your remote SSH server

Problem with Ganymed API

I am writing SSH Client code using Ganymed API's. When I am trying to execute a command remotely through my code it showing nothing and Program execution is not stopping. My putty giving correct output for same command. When I am issuing some basic commands it working fine. I am doing this in windows environment.
I also tried using JSCH API's. But it also giving me same behavior.
Can any one tell me what is wrong and any suggestions please.
Thanks,
Narendra
set channel.connect() and session.disconnect in case of JSCH API's