Shutdown Windows machine from linux terminal

前端 未结 8 1908
眼角桃花
眼角桃花 2020-12-28 21:12

I am running an application on linux machine. By giving the ip address of a windows machine as input, the application must shutdown the windows machine. If the machines run

相关标签:
8条回答
  • 2020-12-28 21:23

    Command to shutdown windows system from linux -:

    $ net rpc -S <ip address> -U <username>%<password> shutdown -t 1 -f

    This command can be issued from bash or even set in cron job to shutdown the computer at a specific time and this command is shipped with many distros by default.

    0 讨论(0)
  • 2020-12-28 21:26

    There may be more setup to do, especially for Windows Vista, Windows 7 and further windows versions, to allow remote shutdown:

    Part A) On the Windows machine:

    1) Add a remote shutdown security policy:

    • run secpol.msc

    • in the program tree, open Security Settings > Local Policies > User rights Assignment

    • Find the entry Force shutdown from a remote system

    • Edit the entry, add the windows user account that will be used for shutdown (ex: nouknouk)

    2) Add registry keys to disable UAC remote restrictions:

    • Run regedit.exe as Administrator

    • Find HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System

    • Create a new registry DWORD(32) value named LocalAccountTokenFilterPolicy and then assign it the value 1

    3) Start remote registry service:

    • Open cmd.exeas Administrator

    • Execute the two following commands:

      sc config RemoteRegistry start= auto

      sc start RemoteRegistry

    Part B) On the Linux machine:

    1) install the package samba-common:

    It depends on your Linux distribution, but for Debian and derivated (Ubuntu, Linux Mint, ...), the apt-get command can be executed like that:

    apt-get install samba-common

    2) To actually shutdown your Windows machine from the Linux one, run the following command:

    net rpc shutdown -f -t 0 -C 'message' -U userName%password -I xxx.yyy.zzz.ttt

    Where:

    • -f means force shutting down all applications (may be mandatory)

    • -t 0 is the delay before doing it (0 means 'right now').

    • -U user%password is the local user and his password on the windows machine (the one that has been allowed to do remote shutdown in part A).

    • -I is the IP address of the windows machine to shutdown.

    0 讨论(0)
  • 2020-12-28 21:26

    It depends on your infrastructure -- how you authenticate to the Windows machines, whether you can configure them yourself, etc. If it were me, I'd put Cygwin on the Windows boxes, then ssh to them and run shutdown -h. There are surely other ways to do it, of course.

    0 讨论(0)
  • 2020-12-28 21:27

    To find your actual Windows username, open cmd and run

    echo %username%
    

    This is the username (not case sensitive) you have to use in your net rpc command

    0 讨论(0)
  • 2020-12-28 21:30

    It's important to note that the above solution will not work if the username in question does not have a password set (at least that's how it was in my case).

    For windows 10 (and below maybe, did not check) users one must go to the firewall settings and enable "Remote Service Management" for the linux box to be able to connect via rpc.

    0 讨论(0)
  • 2020-12-28 21:30

    You need a way to launch a shell on the Windows box so you can run th shutdown command built in to Windows.

    You can install Cygwin for this, then install an SSH daemon in Windows. Once that's running, your Linux box can run commands on the Windows box just as if it were another Linux machine.

    Here are some instructions for setting up Cygwin's sshd in Windows.

    0 讨论(0)
提交回复
热议问题