I have a daily driver, my Mac Studio, and I have the Raspberry Pi as a Lab of sorts. A safe place to bring out Dr. Jekyll, a mirror dimension if you will. I need to access that lab, I can do that through SSH, if you just want to access the terminal, but I like using a GUI. Therefore, I am installing TigerVNC. There are other VNC solutions out there, but I just chose this one. I know I need TigerVNC viewer to access it using the Mac, but life is not perfect. Reading everyone’s divergent opinion on what VNC Server to use takes too much effort. I followed server-world’s instructions.
To install the VNC server it is pretty straight forward. The -y automatically fills in yes for the installation prompt.
freebsd_rpi% sudo pkg install -y tigervnc-server
After installation, you want to run the server for the first time. Using the account you want to use to vnc into the computer, enter the following command.
freebsd@RPI3B ~ % vncserver :1
You will get a prompt to enter password for vnc, and also a view-only password. Once it is done it will create the necessary files.
freebsd@RPI3B ~ % vncserver :1
You will require a password to access your desktops.
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:
xauth: file /home/freebsd/.Xauthority does not exist
xauth: (stdin):1: bad display name "RPI3B:1" in "add" command
New 'RPI3B:1 (freebsd)' desktop is RPI3B:1
Creating default startup script /home/freebsd/.vnc/xstartup
Creating default config /home/freebsd/.vnc/config
Starting applications specified in /home/freebsd/.vnc/xstartup
Log file is /home/freebsd/.vnc/RPI3B:1.log
After this you want to edit the xstartup file using nano.
nano ~/.vnc/xstartup
Add the following lines to the xstartup file and save it.
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
# Start your desktop environment or window manager
exec /usr/local/bin/startxfce4
Now you want to make the xstartup file executable.
chmod +x ~/.vnc/xstartup
To start the vncserver you can just use the vncserver command. It is the vncserver
command followed by the display number.
# vncserver :0
This starts the session on port 5900 + 0
Setup VNC as a Service for Start at Boot
Now you probably want to startup the vncserver at boot time. To do this I finally found one way to do this that works. You first create a script to start the vnc server in your bin directory. Assuming you are in your super user account.
# nano /usr/local/bin/start_vnc.sh
Enter the following in to the script and save. Make sure to updated the entries for your_username
, and the path to your vncpassword
#!/bin/sh
# /usr/local/bin/start_vnc.sh
export USER=your_username
export DISPLAY=:0
export VNC_PASSWORD=/path/to/vncpassword
# Set the environment for VNC and start XFCE
su -l $USER -c "vncserver $DISPLAY -geometry 1280x1024 -depth 24"
I made the script executable for root, and for the freebsd user by running the following command in both sessions.
# chmod +x /usr/local/bin/start_vnc.sh
The next step is to setup a service to execute this at boot time. In the super user account, edit the vncserver config script for rc.d.
# nano /usr/local/etc/rc.d/vncserver
In this file add the following.
#!/bin/sh
#
# PROVIDE: vncserver
# REQUIRE: DAEMON
# KEYWORD: shutdown
. /etc/rc.subr
name="vncserver"
rcvar="vncserver_enable"
command="/usr/local/bin/start_vnc.sh"
load_rc_config $name
run_rc_command "$1"
You then wish to enable the server in the rc.conf file, using sysrc.
# sysrc vncserver_enable=YES
Finally you can start the service to test it out, it will start automatically after the next boot.
sudo service vncserver start
Test out VNC session using MacOS
In your finder enter Cmd+K
and in the “Connect to Server” dialog box, enter :
vnc://<Machine IP address>:5900
Connect, and enter your password when the dialog box pops up. You are now set, you can log in to FreeBSD using the password for the freebsd user.