I have set up a remote machine to use for deep learning — ubuntu 16.04, anaconda 3, jupyter notebook, etc. I've set up openssh with port forwarding, strong keys, no password and that is all working great.
Between sessions, I want to be able to have my machine hibernate/suspend. My understanding is that 16.04 now uses systemd to manage that kind of behavior and that
sudo systemctl suspend is the command I should be using to put that to sleep. I've tried that and it works, yeah!
If I put the machine to sleep from my SSH session the terminal on my laptop then locks up because the other end is now asleep. I don't know that this is causing problems, but it feels not good to me.
If I log out of my ssh session first, then I can't suspend the machine because I'm not authorized.
I'd like to create a little script that lets me, logout then suspend the machine.
I've done a little research, most things I'm finding on google are "how do I log out of ssh and keep my session alive" so I haven't quite hit on the right terms. Also I did find some things relating to dbus or startup, but nothing specifically about systemd. Someone I know suggested the following, but it didn't work. It logged me out, but the machine didn't suspend/sleep/hibernate.
logout && sleep 2 && sudo systemctl suspend
I'm not sure if it was because I needed to authenticate as sudo or because the logout killed the short-circuit evaluation.
So I'm looking for a script I could run that will do the following (order doesn't mater to me as long as the whole thing works).
- make sure I'm authenticated as sudo (if sudo is needed)
- log out of my ssh session
- put the machine into suspend
Or I'm thinking maybe there is a way to logout and then run a script on my local machine to suspend?