Just type <enter>~&
(that's three keystrokes: enter, squggle, ampersand) and ssh will go into the background, and eventually timeout by itself. That's good if you want to just abandon an interactive session in a case like this.
Or, alternatively, put that into a shell script on MyLocalPC and connect in a way that will background the connection:
ssh -f MyLocalPC go-to-sleep
To get started with ssh in general, install openssh-server.
sudo apt-get install openssh-server
On the next restart, this should start up automatically. To connect to the computer remotely, just enter the following in a remote terminal, substituting the ALL-CAPS names for your own:
ssh USERNAME@IPADDRESS
Now, to take care of the dynamic ip forcing you to recheck the IP all the time:
Get a free account on dyndns.com and choose the name you want to type when you connect.
Once that is done, install "ddclient" on the server machine. This will automatically update the IP address for you with dyndns.
sudo apt-get install ddclient
When you run it, it will ask you a series of questions, so have your username, password, and the URL you chose earlier ready to type in. It should also automatically add itself to startup.
That should be it. Now when you ssh, just use the URL you chose instead of your IPADDRESS since this should automatically update if the IP changes.
If you have a router, make sure to forward port 22 to your server! There are lots of guides on this at portforward.com for your specific router.
Best Answer
There are two basic ways this can be done and a workaround:
Either you need to modify
/usr/share/polkit-1/actions/org.freedesktop.upower.policy
, set theXDG_SESSION_COOKIE
environment variable to the appropriate value or usepm-suspend
:Modifying
/usr/share/polkit-1/actions/org.freedesktop.upower.policy
Apply this patch:
(To the
<action id="org.freedesktop.upower.suspend">
tag/section), and it'll work too...or
XDG_SESSION_COOKIE
When you're using the desktop, you'll see that
$XDG_SESSION_COOKIE
has one value, but in an ssh session, it has another. StoreXDG_SESSION_COOKIE
e.g. in a .dotfile or something when the desktop starts and source it in your script that needs to do it over ssh.pm-suspend
Or you could just give up on doing it with
dbus
andUPower
and just issuepm-suspend
as root and get it over with! :-)