How to Enable Screen Sharing via VNC/RDP on FreeBSD Operating System
Categories:
3 minute read
Screen sharing is essential for remote desktop access, troubleshooting, and collaboration. On FreeBSD, you can set up screen sharing using VNC (Virtual Network Computing) or RDP (Remote Desktop Protocol). This guide walks you through installing, configuring, and securing VNC and RDP for remote access on a FreeBSD system.
Prerequisites
Before proceeding, ensure you have:
- A FreeBSD system with root or sudo privileges
- A working internet connection
- Installed Xorg and a desktop environment (e.g., XFCE, KDE, or GNOME) if using a graphical interface
Enabling Screen Sharing via VNC
Step 1: Install a VNC Server
Several VNC servers are available for FreeBSD, including TightVNC, TigerVNC, and RealVNC. TigerVNC is commonly used due to its performance and reliability.
To install TigerVNC, run:
pkg install tigervnc-server
Alternatively, you can install TightVNC:
pkg install tightvnc
Step 2: Configure the VNC Server
After installation, create a VNC password for authentication:
vncpasswd
This command will prompt you to set a password, which clients will use to connect.
Next, create a startup script for the VNC server. Edit or create the ~/.vnc/xstartup
file:
echo "#!/bin/sh" > ~/.vnc/xstartup
echo "exec startxfce4" >> ~/.vnc/xstartup
chmod +x ~/.vnc/xstartup
Modify startxfce4
to match your installed desktop environment (e.g., startkde
for KDE or gnome-session
for GNOME).
Step 3: Start the VNC Server
Start the VNC server on a specific display (e.g., :1
):
vncserver :1
You can stop it using:
vncserver -kill :1
Step 4: Configure the VNC Service for Automatic Startup
Create a system service for the VNC server. Edit /etc/rc.conf
and add:
vnc_enable="YES"
vncserver_args="-geometry 1920x1080 -depth 24"
Then, create a startup script in /usr/local/etc/rc.d/vncserver
:
#!/bin/sh
# PROVIDE: vncserver
# REQUIRE: LOGIN
# KEYWORD: shutdown
. /etc/rc.subr
name="vncserver"
rcvar="vncserver_enable"
command="/usr/local/bin/vncserver"
command_args=":1 -geometry 1920x1080 -depth 24"
pidfile="$HOME/.vnc/%h:1.pid"
load_rc_config $name
run_rc_command "$1"
Set executable permissions:
chmod +x /usr/local/etc/rc.d/vncserver
service vncserver start
Step 5: Secure the VNC Connection
VNC does not encrypt connections by default. To enhance security, tunnel the connection through SSH:
ssh -L 5901:localhost:5901 -N -f -l username remote_host
Then, connect to localhost:1
using a VNC client.
Enabling Screen Sharing via RDP
Step 1: Install an RDP Server
Xrdp is a popular RDP server for Unix-like systems. Install it with:
pkg install xrdp
Step 2: Configure Xrdp
Edit the configuration file /usr/local/etc/xrdp/xrdp.ini
if necessary. The default settings usually work fine.
Enable and start the service:
echo 'xrdp_enable="YES"' >> /etc/rc.conf
service xrdp start
Step 3: Open RDP Ports in the Firewall
If using pf
(Packet Filter), add the following rule to /etc/pf.conf
:
pass in on $ext_if proto tcp from any to any port 3389
Reload the firewall:
service pf reload
Step 4: Connect Using an RDP Client
On a Windows or Linux machine, use an RDP client such as Remmina, FreeRDP, or Windows Remote Desktop to connect to the FreeBSD machine using its IP address.
Conclusion
By following these steps, you can enable screen sharing on FreeBSD using either VNC or RDP. VNC is best for graphical environments, while RDP is more suited for Windows interoperability. Always secure remote access with SSH tunneling, firewall rules, or VPN to protect your system from unauthorized access.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.