This is how it is managed in macOS Server:
and then from the other mac I do:
but it doesn't work, cannot login to remote mac. Why?
If you want to access your server from inside the office, don’t use the public IP - use the server’s local IP (one of the ones starting 192.168....
)
If you want to access your server from outside the office, you may have to configure your office router to forward the relevant traffic to your server. This process is called port forwarding.
I’d
find out the port numbers you need to forward on this page
Google <name of your router> setup port forwarding
for how to enter them into your router - although with many routers, the process is pretty self-explanatory in the admin interface.