Results 1 to 7 of 7

Thread: How Do I Remotely Shut Down My SSH Server?

  1. #1
    Join Date
    Sep 2008
    Location
    Australia
    Beans
    286
    Distro
    Ubuntu

    How Do I Remotely Shut Down My SSH Server?

    I am using an older PC running 12.04LTS, not the Ubuntu Server edition, and use it as a SSH server for backups and file exchange.....nothing very serious and it all works well. It is networking with three other 12.04LTS units.

    I don't have it connected to a screen and this makes it appealing to be able to shut down remotely........when I try "ssh user@IP ***.***.*.*** sudo poweroff" I get the message 'no TTY present and no askpass program specified'. I have searched and googled but the replies are beyond my experience and seem to relate to more serious applications!

    I have tried with similar results......sudo shutdown -h now; halt -p; sudo service ssh stop etc

    The keyboard is still attached so I can shut it down but this means getting off my butt and walking into 'it's' room I usually have to 'blindly' log in again then press the shortcut key combination I have set up.

    Please, Is there an answer to my dilemma?

  2. #2
    Join Date
    Nov 2008
    Location
    Kingdom of cookies
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: How Do I Remotely Shut Down My SSH Server?

    Quote Originally Posted by Plumtreed View Post
    I am using an older PC running 12.04LTS, not the Ubuntu Server edition, and use it as a SSH server for backups and file exchange.....nothing very serious and it all works well. It is networking with three other 12.04LTS units.

    I don't have it connected to a screen and this makes it appealing to be able to shut down remotely........when I try "ssh user@IP ***.***.*.*** sudo poweroff" I get the message 'no TTY present and no askpass program specified'. I have searched and googled but the replies are beyond my experience and seem to relate to more serious applications!

    I have tried with similar results......sudo shutdown -h now; halt -p; sudo service ssh stop etc

    The keyboard is still attached so I can shut it down but this means getting off my butt and walking into 'it's' room I usually have to 'blindly' log in again then press the shortcut key combination I have set up.

    Please, Is there an answer to my dilemma?
    You cant do that unless you allow the user to run sudo without a password for a specific command

    You see - sudo requires a password when you run it - by running it in that form, sudo has no way of asking for a password.

    To allow shutdown to be run without a password,
    Run
    Code:
    sudo visudo
    Add at the bottom
    Code:
    %sudo ALL=(ALL) NOPASSWD: /sbin/poweroff, /sbin/reboot, /sbin/shutdown
    restart (it sometimes needs it), and sudo wont ask for a password for the shutdown command

    The line makes it so that sudo will not ask for a password when running /sbin/poweroff, /sbin/reboot, or /sbin/shutdown with sudo
    Ubuntu Forums Moderation Staff || SandyDNET
    Twitter: @CatchesAStar | Last.fm
    Ubuntu Membership via Forum Contributions

  3. #3
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How Do I Remotely Shut Down My SSH Server?

    Why not just login to the box and shut it down from there?

    It sounds like more work to get it to work with shutdown than it would be just to login and run those commands.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  4. #4
    Join Date
    Sep 2008
    Location
    Australia
    Beans
    286
    Distro
    Ubuntu

    Re: How Do I Remotely Shut Down My SSH Server?

    Quote Originally Posted by CharlesA View Post
    Why not just login to the box and shut it down from there?

    It sounds like more work to get it to work with shutdown than it would be just to login and run those commands.
    That sounds good to me.......how do I do that?

    .....I continue to get an error message about my lack of TTY and Askpass!

    Even after trying Sandyd's suggestion.

  5. #5
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How Do I Remotely Shut Down My SSH Server?

    Just login via putty or a terminal and run the poweroff command.

    Code:
    ssh user@host
    Enter password, then do:

    Code:
    sudo poweroff
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  6. #6
    Join Date
    Jun 2006
    Location
    Brisbane Australia
    Beans
    713

    Re: How Do I Remotely Shut Down My SSH Server?

    OP, this will do what you want:
    Code:
    ssh -t user@host sudo poweroff
    -t forces the allocation of a tty for the command.

  7. #7
    Join Date
    Sep 2008
    Location
    Australia
    Beans
    286
    Distro
    Ubuntu

    Re: How Do I Remotely Shut Down My SSH Server?

    Many thanks for all the considered assistance......I really am a beginner with this server business and very much appreciate your help.

    I immediately have taken to CharlesA's suggestion because it is cleary straight forward and simple....but I have tried the other ideas, they do work.

    Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •