Enabling Pycharm remote debugging in VirtualBox VMs

Set up port forwarding on Virtual box VM network setting

  • stop the vm if already running
  • in network setting, under NAT, click port forwarding
  • create forwarding rule to link port 22 in guest to arbitrary your-port-number (e.g. 2222) in host, & leave other columns blank
  • save configs, test by:
  • start the vm instance
  • ping 127.0.0.1:<your-port-number>

If using connecting to VM on remote server

  • make sure open the port with firewall rule
  • e.g. in CentOS
  • sudo firewall-cmd --zone=public --add-port=<your-port-number>/tcp --permanent

Enable remote debugging on PyCharm

  • under Tools -> deployment -> configurations, add sftp
  • put remote-ip-address as the address, host port configured in previous step as port, alongside with other configurations necessary
  • test in configuration setup page