# rebooting an OS X machine remotely



## MFiend (Mar 17, 2003)

Hi, I have a problem where my OS X server is far away from me and I'm having to login to it remotely. 
This is fine and all, but I installed some software on it and I need to restart. I tried using the shutdown -r now command while logged in through ssh, but that just seems to have brought it to some single user commandline state, where the SystemUIServer, nor my Apache2 install, are running.
Is there something I can do to bring the machine back up to a full gui login, or do I just have to wait until I can get back to the machine in a few days?

Thanks


----------



## michaelsanford (Mar 17, 2003)

Try:

*% sudo reboot*

I always manage to reboot the system once it's already in single-user mode doing that, without the sudo of course, but I presume if a system is already up in multi-user mode it won't let any joe issue reboot or halt.
But since my system is running, I won't test it myself just now.



> REBOOT(8)                   System Manager's Manual                  REBOOT(8)
> 
> NAME
> reboot, halt - stopping and restarting the system
> ...



If you want I can SSH into your system and try it out


----------



## michaelsanford (Mar 17, 2003)

PS if your system is multi-user (and you have the possibility of other users being logged in when you need to reboot) I'd do a *% sudo wall* and tell them the system's going down, because I don't _believe_ reboot sends out messages to all the terminals like shutdown(8) does.

% shutdown -r is supposed to execute reboot(8) as well, but maybe there's something going on that prevents your system actually rebooting, like a firmware issue or something convoluted?


----------



## dixonbm (Mar 18, 2003)

But don't users have to have the Terminal open to see the message when you do %sudo wall

Is there a way to make the message pop up in the aqua interface where most users are probably working?


----------



## MFiend (Mar 18, 2003)

nope, that still didn't work. here is a ps listing of what's going on right now. as stated, there is no SystemUIServer, Finder, or httpd, or anything that should be running if it were booted up through the gui login, as it should do automatically. I'm pretty much as a loss as to what to do until I can get back to physical access.

  PID %CPU %MEM USER    COMMAND
    1   0.0  0.0 root    init
    2   0.0  0.0 root    mach_init
   51   0.0  0.1 root    kextd
   78   0.0  0.0 root    update
   82   0.0  0.0 root    dynamic_pager
  110   0.0  0.2 root    configd
  141   0.0  0.1 root    SecurityServer
  181   0.0  0.2 daemon  ATSServer
  185   0.0  1.0 root    Window Manager
  194   0.0  0.0 root    autodiskmount
  252   0.0  0.0 root    syslogd
  264   0.0  0.0 root    crashreporterd
  268   0.0  0.0 root    netinfod
  271   0.0  0.1 root    mDNSResponder
  275   0.0  0.1 root    lookupd
  297   0.0  0.2 root    coreservicesd
  301   0.0  0.0 root    sshd
  306   0.0  0.0 root    nfsiod
  307   0.0  0.0 root    nfsiod
  308   0.0  0.0 root    nfsiod
  309   0.0  0.0 root    nfsiod
  319   0.0  0.0 root    ntpd
  320   0.0  0.1 root    automount
  330   0.0  0.0 root    inetd
  334   0.0  0.3 root    cupsd
  336   0.0  0.0 root    xinetd
  346   0.0  0.5 root    loginwindow
  348   0.0  0.0 root    cron
  362   0.0  0.4 root    DirectoryService
  363   0.0  0.1 root    sshd
  382   0.0  0.1 root    AppleFileServer
  387   0.0  1.8 root    SecurityAgent
  392   0.0  0.0 root    InternetSharing
  394   0.0  0.0 root    natd
  397   0.0  0.0 root    bootpd
  399   0.0  0.1 root    slpd
  401   0.0  0.1 acooper sshd
  408   0.0  0.0 root    write_store
  402   0.0  0.1 acooper tcsh
  411   0.0  0.0 root    ps


----------



## dixonbm (Mar 18, 2003)

MFiend,

did you specify the file with the message that you wanted displayed?

For example:
%sudo wall /users/home/adminmessage

You can easily create the file in Pico.  The only draw back which i can see is that the message is only displayed in the terminal. So, make sure you have a separate window for terminal open.


----------



## MFiend (Mar 18, 2003)

The message sent to logged in users is not the problem. I am the only logged in user to my machine.
The problem is that, upon "restarting", the machine does not fully boot. By fully boot I mean it does not log in the default user (me) in the gui, and launch all the login items for that user, start the SystemUIServer, Finder, etc. so that I can use something such as vnc to control the machine remotely. I just boots to some in between point where many things are running, but it is obviously waiting for some physical input which I cannot provide remotely.


----------



## dixonbm (Mar 18, 2003)

Are you using Apple's Remote Desktop?  

If so I suggest downgrading to 1.0.  In the update they made it so you had to have someone logged it before you could access the machine.  They considered it a security flaw.  I consider it a pain in the arse.


----------



## MFiend (Mar 18, 2003)

no, I'm just using ssh to login via an external machine. nothing so fancy as apple remote desktop


----------



## michaelsanford (Mar 18, 2003)

MFiend, can you determine which of the following the machine is doing?

1) Rebooting into single user mode; or
2) Just going down to single user mode.

If it's doing the former, you might have something wonky in NVRAM (boot-args).

And can you restart successfully, locally, with an open shell window?

dixonbm, the problem is just rebooting properly, but as for Aqua messages, I'm sure there's a way to make an AppleScript to display pop-up messages for each logged user. But since it's only a terminal window we're concerned about, we don't have to worry about that


----------



## Darkshadow (Mar 18, 2003)

*MFiend* - can you telnet rather than ssh?  Maybe ssh doesn't allow a reboot (I dunno about that one, but it's _something_ to try).


----------



## LordOphidian (Mar 18, 2003)

MFiend... it looks to me, from your process listing, that its rebooting to the Login window... I would guess that its rebooting fine but just not doing the auto login (if you have that enabled).

As for why httpd doesn't come up... I would check your start-up items to make sure you have it configured properly.


----------



## michaelsanford (Mar 18, 2003)

Ah nuts! Of course, System UIServer only starts once a user logs in.

I thought about the auto-login thing but dismissed it since SUIS wasn't running...

Good eye.


----------



## MFiend (Mar 18, 2003)

that's kinda what I had figured too, but is there a way to make the computer log in? 
I wonder if maybe my httpd issues have to do with that I installed apache2 and that might not start until login, unlike personal web sharing (apache 1).


----------



## michaelsanford (Mar 18, 2003)

Yeah it in System Preferences -> Login you select the user to automatically log in and provide the information.

If your computer is at all public (physically I mean) I'd suggest creating a user with almost no privileges that it boots into, so people can't mess around with your machine when it reboots. Or otherwise enable a password-protected screensaver to start after a short delay (you can then use top or ps to make sure it's running).


----------



## MFiend (Mar 18, 2003)

well, it should be set to automatically log in, as that's what it does when I restart it from the gui. but the problem is that it didn't log in when I restarted through ssh


----------



## michaelsanford (Mar 18, 2003)

Oh you already have it configured to auto-login, and it works when you restart locally but not over SSH? hmmmmm


----------



## MFiend (Mar 18, 2003)

right, and I need a way to remotely make the machine log in locally, if that makes sense. I want the machine to pretend as if I'm actually sitting there logging in through the gui


----------



## michaelsanford (Mar 18, 2003)

> hmmmmmmm


 

Ok here's something to try, but I would do this very cautiously!

What I'm trying to achieve by doing this, is to see if rebooting as the root user is equivalent to rebooting from the console, which will auto-log you in, since you said you enabled auto-login.

If you have disabled the root user in Netinfo, re-enable it (Netinfo Manager -> Authenticate -> Domain -> Security -> Enable Root User).

In the terminal
*% sudo pico /etc/sshd_config*

Change:
*PermitRootLogin no*
... to ...
*PermitRootLogin yes*

Then make inetd notice the change:
*% sudo kill -HUP `cat /var/run/inetd.pid`*

Then log in over SSH as _root_ and try rebooting.

I don't suppose I have to go into how big of a hole you've just opened in your system  but at least you'll know if THAT works. If it does, we can work backward from there...

PS The config files might be different in 10.2 I'm not sure, and I think 10.2 uses xinetd, so someone with Jag might have to update my code snippits to work properly.


----------



## michaelsanford (Mar 18, 2003)

Oh yeah almost forgot, don't forget to disable the root user after you're done all this.


----------



## LordOphidian (Mar 18, 2003)

Why don't you just use AppleScript to restart the mac.


```
$ osascript -e 'tell application "System Events" to restart'
```

That does the equivilent of the Restart menu item in the Apple menu.


----------



## MFiend (Mar 18, 2003)

Well, I'm not sure what that did. System Events is now running(it wasn't before), but i'm not sure if it's restarting.


----------



## MFiend (Mar 18, 2003)

it doesn't seem to be working. Now System Events is running, but it hasn't restarted. I don't have to confirm a restart or something, do I?


----------



## LordOphidian (Mar 19, 2003)

I did it from a ssh session with a user already logged in, but the user wasn't prompted for the reboot.

The system just did a normal reboot and came back up. It should be noted though that doing a 'shutdown -r now' for me restarts the box and brings it back up with the auto login completed correctly.


----------



## MFiend (Mar 19, 2003)

well this is crazy. I guess I'll just have to wait until I get back in a few days to figure out what's up with it


----------



## michaelsanford (Mar 19, 2003)

Yeah let us know what's up...


----------



## Captain Code (Mar 19, 2003)

sudo reboot has always worked for me even when there's no user logged in.  For example, my mail server will reboot and it's always sitting at the login prompt with Postfix and QPopper running in the background.


----------



## bossa nova (Apr 12, 2003)

What do I have to do to login using ssh? Is there anything I need to turn on? What about hosts or keys? Does anyone mind writing a quick How To in the How To section?

I can't get it to work across two machines.

thx.
j.


----------

