executing python script for ssh connection not working - python-2.7

I tried to execute a python script that will extablish an SSH connection but it won't work. It is successful when i do it manualy over the python shell, though.
I run a packet capture and i saw that my client machine is resetting the connection for some reason. is it a bug or it just wouldn't work with python2.7?
please help.
Thanks,
Richard

We don't have much information since you didn't send any code, however did you check your firewall parameters ? Maybe your software is not allowed to run the connection

Related

How to make SSH in Google cloud keep running after closing the browser whilst running a .exe-file?

I’m running a gameserver, more specifically a Terraria server on GCP. When I run ./TerrariaServer.bin.x86_64 (exe-file)
I have to input some settings for the server to run. Hence, nohup and & have not worked for me to keep the server running after I close the SSH-terminal. Any suggestions on how to achieve this?
Do not use hohup for SSH sessions. The program will be terminated when the SSH session ends.
Instead use programs like screen or tmux.
Techniques to Keep SSH Session Running After Disconnection

Port forward webserver with SSH thru python 3.6

I have a webserver running which is built with python flask but the the problem is that the server is only running locally.
The solution that I managed to execute was to use the website https://serveo.net which gave me the posibility to broadcast it out on the web. I am running ”ssh -R 80:127.0.0.1:8080 serveo.net” thru subprocess.Popopen() which works great.
But is there any options to use this in native python?
I was thinking about the modules paramiko or sshtunnel but no luck to figure it out.
So, any help would be appreciated about how to run ”ssh -R 80:127.0.0.1:8080 serveo.net” without the shell.
Thanks
I am for now going to keep on using subprocess for this purpose and I do have a SSH.exe in my project directory which is what I am going to run to make sure that it is cross windows machine compatable.
But give me a headsup for better solutions.

Is it possible to SSH in AWS instances using any IDEs such PYCHARM?

I am stuck in a technical issue on a project and I think you the forum could help me out.
I have an EC2 Instance Type:p2.xlarge running on AWS, I cloned a repository in this instance which requires pytorch and cuda dependencies(this point has been taken care of).
Now, The issue is that I wanna work & run this code-base(which is is AWS instance now) somehow in my local pyCHARM IDE. In short, I didn't have proper resources on my laptop to run the repository, so I have to run in an AWS instance but for debugging purposes the local IDE would be a great option.
Is it possible to do that?. In other words, we can do SSH into AWS instance and run code, but all will be done through command line, if we could SSH through PYCHARM and can see the code in AWS here in local machine within PYCHARM and change, debug or run it as it was local but actually it gets executed in the instance.
Please suggest a solution to it.
Thanks in advance.
EDIT-1:
After following, #Cromulent suggestion, I have arrived here
Setting the remote:
Upload happening within the local & remote repo.
I still didn't understand the requirement of syncing the local and remote folders, when I only want to open the remote folder in my PYCHARM IDE and work on it.
I think after this setup, I have to change the code in local copy and the PYCHARM will sync the code in remote copy. How will I be running(using resources-GPUs of the remote Instance, not my local machine.) the remote code in PYCHARM in this scenario, I am just syncing it, for running again I have to ssh through command line and run the script(This does not serve the purpose)?
EDIT-2:
After #Cromulent suggestions.
Actually, it did work, but still, I am not able to run the remote code locally.
I am getting the below error while running any remote script. If I run the same script using ssh in the terminal, the scripts run normally. I tried to fix the problem using this post on StackOverflow, but it didn't work too.
ssh://ubuntu#ec2-52-41-247-169.us-west-2.compute.amazonaws.com:22/home/ubuntu/anaconda3/bin/python -u <08ad9807-3477-4916-96ce-ba6155e3ff4c>/home/ubuntu/InsightProject/scripts/download_flownet2.py
/home/ubuntu/anaconda3/bin/python: can't open file '<08ad9807-3477-4916-96ce-ba6155e3ff4c>/home/ubuntu/InsightProject/scripts/download_flownet2.py': [Errno 2] No such file or directory
The below is the screenshot for the above problem:
PyCharm Professional supports remote Python interpreters (either the globally installed Python interpreter or a virtualenv). It works by creating an SSH connection to the server and then running the code on the remote host. The results are then displayed locally in PyCharm Professional. You can also do remote debugging as well.
You MUST be using the professional version of PyCharm though. The free community version does not support this feature.
You can find the documentation here:
https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html
One more solution is to deploy a Jupyter Notebook on your remote server. Then you will be able to use it from PyCharm Professional Edition.
Don't forget to make rules for the jupyter ports (e.g. allow all 8888) in your AWS console and in your instance.
To configure a remote interpreter for your notebook do this (source):
Open the Jupyter Notebook page of the Settings/Preferences dialog.
On this page, select or clear the Markdown cells rendering enabled option, and specify the username and password. Note that for the
single-user notebooks these fields are optional - leave them blank.
Fill in the username (for JupyterHub) and password.
Click the link Configure remote interpreter. You'll find yourself at the Project Interpreter page.
Configure the remote interpreter, as described in the section Configuring Python Interpreter.
You will want to configure a remote interpreter.
I tried the above approach but it didn't work for me. I have edited my post so that I can get additional input from the community, but I didn't any after the first answer was posted.
My friend actually figured out a secondary way to fix the issue. He actually uses "NOMACHINE" on the local machine and open connection to the remote desktop. Then you can directly install PYCHARM in the remote machine and work in there. I hope this will help others.
The solution is in his blog post. (Thanks to Shaobo Guan)
Another solution would be to use VNC instead of NoMachine

Debugging a Travis CI process?

I am trying to figure out why my Travis CI tests fail here. It looks like an infinite loop in one of the programs and I'm eager to run gdb there and take a look inside. I assume that the Travis instance is behind NAT, so just connecting to a GDB server would be complicated. Is there a way to make the gdb server connect to me? Do I have any alternatives?
Here's what I found:
https://github.com/fniephaus/travis-remote-shell
This is a project that uses Ngrok to open a TCP port and then creates a reverse shell there. I hadn't tried it though.

Execute command or transfer files to remote windows machine

What I'm actually looking for is the equivalent off ssh connection in windows environment. As per requirement, my controller machine can connect to remote machine with username password using some kind of utility/protocol such as ssh or telnet or rpc or tpc and using this session I can transfer files or execute command on remote machine. This connection execution must be done without any intervention from remote machine, i.e. I don't need to install any module or install any utility on remote machine or run any script.
My both controller and remote environment are windows.
Can someone suggest me python module or utility, using which I'll be able do this ?
I explore few option however I'm not sure if they are the best way to do so. Pleas provide your thoughts on this too.
connect using psexec utility through popen.
using socket to communication channel, however I'm not sure if I can execute any command using this channel.
making use of Telnet. but I didn't explore the python module to make telnet connection and execute command.
using module such as Pyro or rpyc.
Any help is appreciated. Thanks a lot in advanced.
take a look at the pexpect module. It can be used for ftp, ssh ...
pexpect doc