You can use SSH, port forwarding, and dynamic dns to acomplish this.
SSH
This gives you a 'remote command line' from any other machine to your Raspberry Pi. Read more here : https://www.raspberrypi.org/documentation/remote-access/ssh/
Port Forwarding
It is likely that your router will block incoming connections from other internet connected machines (outside your home/local network). So to allow thew connections to come in you'll likely have to configure your router to allow connections (either from a known set of IP addresses, or to a specific port - in the case of SSH that will be port 22). Essentially you'll need to tell the router that any requests it receives on port 22 should be handled by the Raspberry Pi so send those requests over to the Raspberry Pis IP address.
Read more on this here : https://www.raspberrypi.org/documentation/remote-access/access-over-Internet/README.md
Dynamic DNS
Each time your router connects to the internet it gets an IP address, the address it gets usually changes semi regularly, so you cannot always be sure you should be using the same IP address. To get around this you use Dynamic DNS - this lets you configure a fully qualified domain name (FQDN, for example mypi.example.com
or kenspi1.dyndns.com
) and has your router (or Pi) update the domain name with the correct IP address regularly. Now, instead of have to SSH to a different IP address each time you just SSH to the fully qualified domain name.
There are lots of tutorials on each of these, and in all there (because it's a common questions/request)