One-Liner To Shutdown Remote Host

To shutdown the local auto immediately, you lot execute this ascendance every bit root or nether sudo:
 $ shutdown -h at nowadays 

If it is a remote server that you lot desire to shutdown, it could hold out slightly to a greater extent than involved.

You demand to accept root privileges to shutdown a machine. However, many systems are configured to block root from logging inward remotely usingssh. So, you lot demand to ssh inward every bit a regular, non-root user, together with overstep the sudo ascendance to shutdown host.

 $ ssh -t peter@192.168.1.112 'sudo shutdown -h now' peter@192.168.1.112's password:  [sudo] password for peter:  Broadcast message from root@tiger (pts/2) (Sat April thirteen 10:56:30 2013):  The organisation is going downward for organisation stop NOW! Connection to 192.168.1.112 closed. $  

Don't forget the -t sshparameter to "force pseudo-tty allocation". Without it, the to a higher house one-liner volition neglect alongside this message.

 sudo: no tty acquaint together with no askpass programme specified 

Note that you lot volition hold out prompted twice to type inward your password. The outset fourth dimension is for ssh; the second, sudo.

To avoid typing the outset password, gear upwards password-less login. This is a topic yesteryear itself, together with I won't become into it here.

To avoid the second, configure sudo to non prompt peter for his password when he issues a sudo command. This is done yesteryear editing the /etc/sudoers file.

 $ visudo 

Insert the next business to the file:

 peter ALL=(ALL) NOPASSWD: ALL 

The to a higher house business allows peter to sudo every bit anybody from whatever host together with run whatever ascendance without beingness authenticated. Only create this afterward you lot accept considered its safety ramifications. You accept been forewarned.

Now run the one-liner again.

 $ ssh -t peter@192.168.1.112 'sudo shutdown -h now' peter@192.168.1.112's password:   Broadcast message from root@tiger (pts/1) (Sat April twenty 21:40:50 2013):  The organisation is going downward for organisation stop NOW! Connection to 192.168.1.112 closed. 
The user is alone prompted once, yesteryear ssh, to larn into a password.

Berlangganan update artikel terbaru via email:

0 Response to "One-Liner To Shutdown Remote Host"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel