How to enable sshd from the FreeBSD 8 install’s fixit environment?

How to enable sshd from the FreeBSD 8 install’s fixit environemnt?

So there are lots of documents out there on how to do something in fixit and some times (most the time) those are long drawn out processes with a lot of typing.

What if you could copy and paste? Well, you can’t. But you could if you could ssh in right.

So lets boot to the FreeBSD 8 Installation DVD and see if we can enable sshd.

I just got it to work so let me document my steps:

  1. Run ifconfig to find what ethernet controller you have. Mine was em0.
    fixit# ifconfig
  2. Now assign an IP address. Make sure to find an open IP Address that is not already in use.
    fixit# ifconfig em0 inet 192.168.0.25 netmask 255.255.255.0

    That is it for configuring your IP address. You may be asking yourself, what about the DNS server and the default route? Well, you only need those if you are connecting from a different subnet and since you are booted to a fixit environment, I assume you are on the same subnet. Just in case you aren’t, you can enable DNS and give yourself a default route with these commands:

    fixit#
    fixit#
    echo nameserver 192.168.0.1 > /etc/resolv.conf
    route add default 192.168.0.1
  3. Create the directory where the default sshd configuration and keys are stored.
    fixit# mkdir /etc/ssh
  4. Copy the sshd_config to this directory.
    fixit# cp /dist/etc/ssh/sshd_config /etc/ssh
  5. Change the configuration file to allow root logins.
    fixit# echo PermitRootLogin yes >> /etc/ssh/sshd_config
  6. Create the rsa1, rsa, and dsa keys.
    fixit#
    fixit#
    fixit#
    ssh-keygen -t rsa1 -b 1024 -f /etc/ssh/ssh_host_key -N ”
    ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ”
    ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ”
  7. Make sure that root can find a shell.
    fixit# ln -s /mnt2/bin/csh /bin/csh
  8. Make sure root has a home directory.
    fixit# mkdir /root
  9. Start the sshddaemon.
    fixit# /mnt2/usr/sbin/sshd
  10. Prepare the environment for login. We probably want similar environment variables, because the defaults won’t work, since most our binary files are in subdirectories of /mnt2.
    fixit#
    fixit#
    fixit#
    env > /root/env
    echo ‘setenv ENV $HOME/env’ > /root/.cshrc
    echo sh >> /root/.cshrc
  11. Now try to connect using ssh and the root user. There should be no password requested. If you need a windows ssh client, use PuTTY.Note: There may be some errors on setting the environment variables when you log in but they aren’t going to hurt anything and the ones you need should work.

Well, that was a lot easier than I thought it would be. Only took me a short time to figure out.

Hopefully if you search any search engine for this term, you will find this post:
freebsd fixit sshd


Copyright ® Rhyous.com – Linking to this article is allowed without permission and as many as ten lines of this article can be used along with this link. Any other use of this article is allowed only by permission of Rhyous.com.

6 Comments

  1. deanet says:

    thanks... it's awesome.. now lets run zfs installation script 🙂

  2. s0ta says:

    thanks a lot... its really helpful

  3. Matthew Willsher says:

    Thanks for the guide - most useful. I did find a slight problem if you need geom tools. GEOM_LIBRARY_PATH doesn't get exported so gpart etc. can't see the required libraries. This is fixed after login via ssh by running:

    export GEOM_LIBRARY_PATH

  4. Thanks, this is really useful! Just tried it in vmware and it works like a treat.
    There is a small typo in step 5, you obviously want to echo PermitRootLogin to /etc/ssh/sshd_config rather than /dist/etc/ssh/sshd_config

  5. rhyous says:

    Thanks phatfish for the update.

    I mostly did the .cshrc the way I did to make it easy to type and try to get the same environment as best as I could.

    Adding a USB stick is great idea to eliminate the pain of typing it all in.

  6. phatfish says:

    Hi,

    Your post really helped doing a complex setup from Fixit. Being able to ssh in and copy/paste commands made things a LOT faster!

    If anyone else comes across this post, i tweaked the steps a bit and dumped them in a .sh file. If you run the script bellow from a usb stick, it will set everything up. It uses dhcp for net setup, and i changed the .cshrc a little because the one rhyous created in his post behaved a bit weird for me (no command history for one).

    Thanks goes to rhyous 🙂

    #!/bin/sh
    # setup network (set the correct device for your system)

    mkdir /var/db
    ifconfig re0 up
    sleep 5
    dhclient re0

    # setup sshd

    mkdir /etc/ssh
    cp /dist/etc/ssh/sshd_config /etc/ssh
    echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config

    mkdir /usr/bin/
    ln -s /dist/usr/bin/ssh /usr/bin/ssh

    ssh-keygen -t rsa1 -b 1024 -f /etc/ssh/ssh_host_key -N ''
    ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
    ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''

    # setup login shell for root

    mkdir /root
    echo "setenv PATH '/bin:/sbin:/usr/bin:/usr/sbin:/stand:/mnt2/stand:/mnt2/bin:/mnt2/sbin:/mnt2/usr/bin:/mnt2/usr/sbin'" > /root/.cshrc
    echo "setenv EDITOR '/mnt2/usr/bin/ee'" >> /root/.cshrc
    echo "set prompt='Fixit# '" >> /root/.cshrc
    ln -s /mnt2/bin/csh /bin/csh

    # start sshd

    /mnt2/usr/sbin/sshd

Leave a Reply to Matthew Willsher

How to post code in comments?