Enable SSH on a Mac in single user mode

9

3

I have an iMac that I can access only in single user mode, because of serious hardware damage. I attached to it another computer with an Ethernet cable. I would like to login remotely to the iMac through SSH. The iMac is running OS X 10.6.4.

I came across similar answers but what I tried always failed.

I tried systemsetup -setremotelogin on and it returns the following error message:

systemsetup[63:903] setInetDServiceEnabled failed for ssh because authorizationRef is NULL!

While launchctl load -w /System/Library/LaunchDaemons/ssh.plist gives:

DNSServiceRegister("ssh"): -65563
DNSServiceRegister("sftp-ssh"): -65563
bind(): Can't assign requested address
launch_msg(): Socket is not connected
launchctl: CFURLWriteDataAndPropertiesToResource(/var/db/launchd.db/com.apple.launchd/overrides.plist) failed: -10

What should I do?

Ralphtor

Posted 2012-06-28T22:47:06.560

Reputation: 91

Can't assign requested address sounds to me like it doesn't have any kind of network connection. I think in single-user mode you'd have to use ifconfig or ifup to turn enable networking. – Blacklight Shining – 2012-07-09T10:17:42.980

@BlacklightShining thanks! I have little experience with these commands, I guess that with a Mac it would be more appropriate to use networksetup or ipconfig, however. Do you have an idea about what commands I should give in order for another computer to connect to the iMac via a single Ethernet cable? Or, in alternative, to connect the iMac to a wi-fi network protected with WPA2? – Ralphtor – 2012-07-09T11:44:51.130

I'm not sure myself. You can get the manual page for almost any program with man $program_name, by the way. I'll take a look and see if I can come up with something for you to try… – Blacklight Shining – 2012-07-10T11:57:17.890

Answers

7

Looks like you need to load some more plists:

launchctl load /System/Library/LaunchDaemons/com.apple.kextd.plist
launchctl load /System/Library/LaunchDaemons/com.apple.notifyd.plist
launchctl load /System/Library/LaunchDaemons/com.apple.configd.plist
launchctl load /System/Library/LaunchDaemon/com.apple.DirectoryServices.plist

Then do what you tried before:

launchctl load -w /System/Library/LaunchDaemons/ssh.plist
systemsetup -setremotelogin on

After that, I think you can simply plug the Ethernet cable into both computers to create an ad-hoc network. ifconfig en0 | grep inet on the target machine should get you its IP address, and then you're all set. :)

Blacklight Shining

Posted 2012-06-28T22:47:06.560

Reputation: 2 127

Thanks for your advice, the first commands were good. Unfortunately to the last command the computer answered with: DNSServiceRegister("ssh"): -65563, DNSServiceRegister("sftp-ssh"): -65563, with these two messages repeated twice. So I cannot connect with ssh. I remember vaguely to have changed the port for the incoming ssh connections, so it is probably my fault, but I would appreciate any help – Ralphtor – 2012-07-10T15:18:44.507

I must clarify: launchctl load -w /System/Library/LaunchDaemons/ssh.plistgives me the error I mentioned in the previous comment, while systemsetup -setremotelogin onkeeps giving setInetDServiceEnabled failed for ssh because authorizationRef is NULL! – Ralphtor – 2012-07-10T17:08:34.650

Do you remember how you changed the port? Could you maybe change it back? That might not do anything, but it's worth a try… – Blacklight Shining – 2012-07-10T21:09:25.920

I read the configuration files, it seems that the port is correctly set to 21. Probably this was not the problem because I followed the instructions for another Mac and ssh gave the same errors. For honesty sake the Mac I tested was a Mac mini with Lion and it complained that com.apple.DirectoryServices.plist does not exist any more (as it was removed in Lion), but that should not be a big issue because ssh gave me exactly the same error as in the iMac. – Ralphtor – 2012-07-11T18:38:45.087

3

Three solutions you could consider. First, try target disk mode. If single user mode works, then target disk mode should work as well.

Once it is started in target disk mode, plug it into the other system you have (using firewire), and tell the second system to boot externally (hold down option on boot). Once the OS in the damaged system boots using the local systems hardware, open System Preferences and click on “Sharing” Select the checkbox next to “Remote Login” to enable it.

Shut down and restart, and you should have SSH up and running.

A second option is to remove the hard drive from the damaged system and boot from it externally (in an external enclosure) or place it inside your functional system and boot from there.

If neither of those work, but you are running single user, consider

cd /Library/Preferences
echo -n enabled > com.apple.ScreenSharing.launchd

This will turn on screen sharing, use that to access System Preferences on the remote machine, make the changes (turn on SSH) and you are functional.

Everett

Posted 2012-06-28T22:47:06.560

Reputation: 5 425

0

Why not launching sshd directly? Once the network is up /usr/sbin/sshd -p 4212 will open a ssh server on port 4212.

cdelacroix

Posted 2012-06-28T22:47:06.560

Reputation: 101

Thanks for your answer. I executed the command (out of curiosity I'd like to ask why it was needed to write the complete path /usr/sbin/). If i run top on the iMac I see a process called sshd, so it should have worked. However when I connect with a computer with an Ethernet cable, look for the IP of the iMac with ifconfig, and run ssh 192.168.0.3 -p 4212 on the other computer it says ssh: connect to host 192.168.0.3 port 4212: Operation timed out – Ralphtor – 2012-07-19T22:33:13.640

I should also mention that shutdown -h now now does not work to shut down the iMac. I had to shut it down manually – Ralphtor – 2012-07-19T22:36:09.347

I tend to write full paths in my answers to avoid surprises due to badly configured PATH variables. I use that command often and it works for me, on 10.6 and 10.7, although not in single user mode I have to admit. Are you connecting in ssh as root? – cdelacroix – 2012-07-20T08:25:33.470

How do I connect as root? I tried ssh root@192.168.0.3 -p 4212 and I even tried with the usernames of other accounts that are set up in the iMac and it always times out. If I use another port, instead of 4212 it complains "Connection refused", so something should be working, because it appears to answer to the right port. However I still can't connect – Ralphtor – 2012-07-20T12:05:45.183

The server might not be able to spawn a shell? You can try ssh -vvv root@192.168.0.3 -p 4212 to see (really) verbose output from the client side, or even on the server side put ssh in debug mode to see what is happening (with sshd -d -p 4212). – cdelacroix – 2012-07-20T13:03:55.773

It is stuck on the connection. The server doesn't report anything after Server listening on 0.0.0.0 port 4212, the client says debug1: Connecting to 192.168.0.3 [192.168.0.3] port 4212. and after a while complains that the operation is timed out – Ralphtor – 2012-07-20T14:20:14.880