N4BB

Credit for the original information used in making this how-to goes to TylerL82 over at the SomethingAwful.com forums. Written up here by Jonathan Bare.

So while you have your Apple TV open and you’re installing a new hard drive or just following along with the people over at SomethingAwful.com forums to get Xvid working, you might as well un-break SSH so you can access the Apple TV remotely.

Opening the Apple TV and connecting the hard drive to your Intel Mac are covered in the hard drive upgrade and elsewhere, so we’ll skip those steps and jump right to the point where you have the OSBoot and Media volumes mounted on your Mac.

This process assumes using an Intel Mac because the sshd binary may or may not be the same in the PowerPC version of Mac OS X; we haven’t checked. If someone would like to try using the PowerPC binary and let us know if it works, that would be great!

There are 2 ways to go about this; using the finder, or via the terminal. The finder method is probably best if you aren’t sure what is going on, whereas the Terminal method is quicker if you are confident.

Step 1 – Using the Finder

Once you have OSBoot mounted in the Finder, double click on its icon. You’ll see something like this:

From the Finder’s Go menu, select Go To Folder, or press Command-Shift-G. Type in /Volumes/OSBoot/usr/sbin/ and click Go.

Open a new Finder window and do the same thing to go to a folder, this time, however, select /usr/sbin/. This is the same folder located on your Mac’s hard drive.

From the Mac’s sbin folder, drag the file “sshd” to the Apple TV’s sbin folder. Your cursor will change in to the green plus sign to indicate that you are making a copy of the file.

Note: If you have accidentally ended up in /usr/bin instead of /usr/sbin and you accidentally copy the “ssh” file instead of “sshd”, you’ve made a big mistake and ssh will not work on your Apple TV. Be sure you are working to and from the respective /usr/sbin directories.

You now have sshd installed on your OSBoot volume. Now we need sshd to start when the Apple TV boots up.

In the OSBoot window, choose Go To Folder again and this time, enter /Volumes/OSBoot/System/Library/LaunchDaemons/.

If you open the Apple TV’s ssh.plist file from the LaunchDaemons directory, you’ll see why we need to replace it. Apple left a dummy plist file to throw us off the trail.

You could copy the ssh.plist file from the same location in your Mac’s /System/Library/LaunchDaemons/, but for simplicity, we’ve included the contents of the plist here (if you do copy from your Mac, ensure SSH is enabled in System Preferences -> Sharing, or it won’t work – thanks to Adam Gill). Using TextEdit, BBEdit, or your favorite text editor, copy and paste this text, replacing the original ssh.plist contents:

Label
com.openssh.sshd
Program
/usr/libexec/sshd-keygen-wrapper
ProgramArguments

/usr/sbin/sshd
-i

SessionCreate
Sockets

Listeners

Bonjour

ssh
sftp-ssh

SockServiceName
ssh

StandardErrorPath
/dev/null
inetdCompatibility

Wait

 

Close the file and save it. In a nut shell, the ssh daemon is activated by launchd whenever an incoming connection on port 22 is detected.

Step 1 – Using the Terminal

Firstly, copy the sshd binary from your Mac to the AppleTV drive:


cp /usr/sbin/sshd /Volumes/OSBoot/usr/sbin/.

Next, copy the ssh.plist file over, so launchd knows to start sshd on boot:


cp /System/Library/LaunchDaemons/ssh.plist /Volumes/OSBoot/System/Library/LaunchDaemons/ssh.plist

Alternatively, you could use the contents of the file from above to create an ssh.plist file.

Step 2

Unmount the OSBoot and Media volumes, reassemble your Apple TV, and power it on. You need to get the IP address of the Apple TV from the Settings menu, once you know that, open a Terminal window from your Mac (or any OS that has ssh installed) and type:

ssh frontrow@your.apple.tv.ip.address

Press return. Type “yes” when it asks if you want to permanently store the key. Then enter “frontrow” as the password.

You’re in.

Now what?

SSH opens up a lot of doors to accessing the Apple TV. For example, you can now type sudo /usr/sbin/AppleFileServer and cause the built-in Apple File Protocol (AFP) server to start. Then you can connect to the Apple TV from your Mac by using the Connect to Server command in the Finder. AFP, SCP or SFTP can now be used to copy files to the Apple TV!!

You can type ps auxww to see a list of running processes on your Apple TV. (Hey, what is /usr/bin/ripstop and why is it running under the frontrow user?)

One thing we’ve already learned from SSH is that the root filesystem on the Apple TV (aka OSBoot) is apparently mounted as a read-only filesystem. That means it’s not initially possible to copy any files to the root mount point (/etc, /usr, /var, for example) while it is running. TylerL82 has commented to point out you can remedy this with the sudo mount -uw / command.

It’s also important to note that any changes you make to the OSBoot volume will be wiped out by a Factory Restore of the Apple TV. It appears that a disk image of the stock Apple TV operating system exists on the unlabeled partition on the drive and is used to restore the OSBoot volume when Factory Restore is selected.