I am trying to connect to remote machine by python script. Both the machines can be linux/windows.
I have to connect to various remote machines and it's not feasible for me to install or write some code on the remote side. I know the ip, username and password of the machine and i tried various options but was unsuccessful.
How shall I proceed.
Maybe you can use SSH to connect to a remote server.
paramiko will be good idea, it can use to connect linux/windows.
http://pxnet2768.pixnet.net/blog/post/157228756-%E7%B3%BB%E7%B5%B1%E9%81%8B%E7%B6%AD%E5%B7%A5%E7%A8%8B%E5%B8%AB%E7%9A%84%E6%B3%95%E5%AF%B6%EF%BC%9Apython-paramiko
Related
I want to create a directory in my remote system using python script or by socket programming. I have remote system's Username, password and IP address. I am able to do this in my local machine but not in remote. Please help!
Download Putty then connect to remote system) and in terminal write mkdir foldername
To create a directory on a remote machine, you will have to first connect to it.Telnet and SSH and SSH is used to connect to remote machines. Obviously TELNET or SSH service should be running on the remote machine, otherwise you won't be able to connect.Since in case of Telnet,data is transfered in plain text, it's better to use SSH protocol.
Once connected to the remote machine using SSH, you will be able to execute commands on the remote machine.
Now since you want to do everything in Python, you will have to write a complete SSH client in Python. Which is greate for learning, because you will learn about socket programming and cryptography.
If you are in a hurry, you can use a good SSH library.
If you are getting network connection error, please check whether SSH is installed in the remote machine or not. If yes, then check firewall settings.
I'm new to Python yet managed to create a lot of good stuff for myself. The problem I faced is how to connect to an SQL database on a remote machine (VPS, VDS, Cloud)
I know that you would likely point me out to other answers on StackOverflow. Unfortunately, there is no one solved question on the website. None of the solutions worked for me.
One more time, I don't want to connect to an SQL database on a local machine. I need to access it remotely.
Can anyone provide me with working instructions?
[https://stackoverflow.com/questions/46913504/connecting-to-mysql-db-via-ssh-with-python][1]
[https://stackoverflow.com/questions/47069829/mysql-and-python-via-ssh][1]
[https://stackoverflow.com/questions/21903411/enable-python-to-connect-to-mysql-via-ssh-tunnelling][1]
[https://practicaldatascience.co.uk/data-science/how-to-connect-to-mysql-via-an-ssh-tunnel-in-python][1]
As you can see, there are numerous upvotes. But none of the approaches helped the topic starter. Otherwise, it would be marked as solved.
If you have a VPS that you can access via SSH then you can also use SSH to forward the port of the MySQL server on the VPS to your local machine.
This is something you would do for the development process of your application
Use this command to forward the remote ssh port to your local machine.
ssh -L 3306:localhost:3306 username#hostname
This way you will be able to access your VPS's MySQL server trough port 3306 on your local machine.
Here is some SSH documentation.
https://www.ssh.com/academy/ssh/tunneling/example
It is also possible to create ssh tunnels from within python but this is not recommended for a use case like yours.
Anyways, if you want to learn about this, you can read about it here
https://github.com/pahaz/sshtunnel/
A(remote mysql server) <-------> B( remote Staging server) <--------> C(my laptop)
mysql server is running on machine A having IP 192.168.39.151. There is another remote server B having IP 192.168.33.150 which can access mysql server running on A.
machine C is my laptop and my intension is to access mysql server and I dont have the access. So every time I have to ssh to B(staging server) to access mysql server.
Can it be possible to access mysql server from C(my laptop) without login into B(Staging server) so my python scripts can work on my laptop itself?
I guess port forwarding is the solution. Can somebody tell me the steps to setup port forwarding for this case. all the machines re running on Linux.
Please tell me if there are other solutions.
I have a remote development Linux machine (with own IP address) in a VPS provider. I also have my machine that connects to internet via a router. I want a Django process in the server to connect to a pydev debug server on my machine.
I use pydev debugger, this configuration tells django at any host to connect to the given host/port where the debugger is running.
pydevd.settrace('localhost', port=5678, suspend=False)
How to connect to the VPS from my desktop? NAT is impossible since the router and DHCP is not in my control. VPN seems feasible but complicated.
I think the best way to resolve it in this case would be doing a port forwarding through ssh -- I don't have any specific instructions for that, but google has plenty ;)
I'm writing a small python program locally as i don't have root access on the server. It basically does a lot of mysql queries using python MySQLdb module.
The thing is I cant use MySQLdb with the server, as the mysql server is hosted locally and I need to ssh into the server and then use mysql from there.
Is there any module available where I can connect to a mysql database via SSH.
At the moment I can connect to the mysql instance using SSH credentials (IP, User, Pass)
I also have the user/pass for the mysql instance and I'm pretty sure it runs on 127.0.0.1/localhost.
If you're set on Python, I would use paramiko:
https://github.com/paramiko/paramiko
This seems to be one of the most widely used Python SSH libraries. There are some other StackOverflow questions that address how to do this.
How to open an SSH tunnel using python?
SSH Tunnel for Python MySQLdb connection
The main idea is to create a tunnel with paramiko and then connect to the localhost port through which you are tunneling traffic to the remote server using the Python library MySQLdb.