How to find the port number for a remote server? - python

I'm trying to set up SSH Python interpreter on Pycharm. In the wizard, it is askin for:
Host
Username
Port
I know the the name of my remote workstation and my username. But where can I get the port number from? does it require settings of Pycharm on remote server?
Instructions are not clear.
I have W10 on both sides.
https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html

On your Windows 10 remote server you have to enable/install an SSH server. Windows does have a native one, I saw that you can also use OpenSSH now.
And your SSH server should run on port 22 by default.

Try default port 63342 of pycharm besides ssh connection port on 22 :
https://www.jetbrains.com/help/pycharm/settings-debugger.html

You have to setup an SSH server on your remote machine in order to connect to it.
See: https://phoenixnap.com/kb/ssh-to-connect-to-remote-server-linux-or-windows
Once you have done that, the host will be the address of the remote machine, the username and password will be the credentials of a user that exists on the remote machine and the port will be a number that you have chosen when you were setting up the SSH server (22 by default).

Related

How to connect Linux Virtual Machine from its host computer?

I'm creating a simple chat app using Python.
The server code is in the Linux VM (I am using Virtual Box), and the client code is in the Windows 10 computer where the Virtual Box is installed.
I'm trying to connect it with the Python socket.
It works when I ping both machines to each other.
My problem is what port should I put in the client code:
Client
import socket
import subprocess
cliente = socket.socket()
try:
cliente.connect(('192.168.1.33',9090))
cliente.send("1")
I tried every port available; however, nothing works. I think I am missing something to make this work.
First, You need to make sure that the port number passed to bind function in server code in Linux VM is the same port number used by connect function in your client.
Check this simple server-client example in python which is using port 12345 :
https://www.tutorialspoint.com/python/python_networking.htm
Second, (based on your comments) the IP address that should be used in client connect function is the IP address of the machine running the server code which is in your case the Linux VM. Try to run the shell command ifconfig in the Linux VM to get the IP address.
If this address didn't work you can change the network settings of the virtual machine to bridged instead of NAT and try again the ifconfig command and get the new IP address.
Doing SSH from the host machine to Linux Virtual machine will work great!!

Pycharm IDE coding on remote server with ssh

I wonder if there is any way to coding python with remote server data and run the python script on remote server with pycharm only installed on my local machine?
The remote server can be access by two ip address (ssh and ftp each), id and password.
But when I try to use pycharm professional project interpreter, there always an error like this (the ip address I used is for ssh):
I know the easiest way is install jupyter notebbok on my remote server, but I don't have permission to do that.

PyCharm: Configuring multi-hop remote Interpreters via SSH

To connect to the computer at my office I need to run ssh twice. First to connect to the host-1 and then from host-1 to host-2 and each one has different credentials. However the configuration menu in Pycharm only accepts one ssh tunnel.
Configure Remote Python Interpreter dialog box
Is there any way to set a multi-hop ssh to have access to the interpreter and data files on the host from local?
You can use port forwarding on ssh.
1. Open a terminal and run:
On your local system:
ssh -L 6000:<target_server_ip>:22 <proxy_server_user>#<proxy_server_ip>
You should be connected to the proxy now. You can substitute 6000 with any port.
2. (optional) Test
Now you can ssh into the target server on another terminal with:
ssh -p 6000 <target_server_user>#localhost
3. Configure PyCharm
Keep in mind not to close the first terminal!
The same goes for the PyCharm. Just set the remote interpreter connection through ssh with the following configuration:
host: localhost
port: 6000
user: target_server_user
PyCharm seemingly parses the local .ssh/config too.
If you already have configured ssh hopping there, you can just specify the target server in your pycharm ssh-config.
~/.ssh/config (source)
Host bastion
Hostname bastion.domain.com
Port 2222 # a non-standard port is a good idea
User ironicbadger
Host servera
Hostname servera.lan.local
User servera-user
ProxyCommand ssh bastion -W %h:%p
in pycharm:
Host servera, User name server-user
For users on ssh version 7.3 or later this can be simplified using the ProxyJump parameter.
Host bastion
Hostname bastion.domain.com
User bastion-user
Host servera
Hostname servera.lan.local
User servera-user
ProxyJump bastion

Configuring Remote MYSQL with a Dynamic IP

I am connecting my python software to a remote msql server.
i have had to add an access host on cPanel just for my computer but the problem is the access host, which is my IP, is dynamic.
How can i connect to the remote server without having to change the access host everytime?
thanks guys, networking is my weakness.
Your best option is probably to find a [dynamic DNS] provider. The idea is to have a client running on your machine which updates a DNS entry on a remote server. Then you can use the hostname provided instead of your IP address in cPanel.
There is a bash script for linux which can be run to check continuously whether the IP has changed and update the providers record if necessary. It is for cPanel and requires editing the code to insert the credentials, which is trivial.
Download from github

Lost connection to MySQL server at 'reading initial communication packet [duplicate]

This question already has answers here:
Lost connection to MySQL server at 'reading initial communication packet', system error: 0
(40 answers)
Closed 9 years ago.
I want to establish a connection between my local machine and MySQL database server via Python.
Can someone tell me how to "bind-address with localhost"?
Can someone tell me how to "bind-address with localhost"?
This is a MySQL configuration directive.
Edit the global my.ini file, in the [mysqld] section:
[mysqld]
# -- various other settings
port = 3306
bind-address = 127.0.0.1
# -- other settings
Save this file, and then restart your server.
Edit
If you want to connect to your local Windows instance of MySQL, simply use 127.0.0.1 as the server's address.
If you want to connect to your remote server, the one running Linux then it is a bit complicated:
First, make sure MySQL is listening on the public IP of the Linux server. Change the line bind-address = and set it to the public IP of your server.
Make sure port 3306 isn't blocked by any firewall.
The user that you use to connect to the server needs to have rights to connect from a remote IP. By default, users are only given rights to connect from localhost - in other words they can only connect if the program is running on the same machine as the server itself.
To grant a user access from a remote IP, run this command from the mysql> shell when logged in with the MySQL root user:
GRANT ALL on somedb.* to someuser#8.8.8.8 identified by 'somepassword';
If you want to grant access to someuser from any remote IP:
GRANT ALL on somedb.* to someuser#% identified by 'somepassword';
After those steps, make sure to restart the MySQL server so it will read the changes in the configuration.

Categories