树莓派 VNC连接

1、图形化界面下载

先SSH远程连接树莓派,更新一下源,然后重启

sudo apt-get update
sudo apt-get upgrade
reboot
再次进入系统后,下载桌面环境,时间有点长

sudo apt-get install ubuntu-desktop
下完后还没完全成功,我们需要跟着提示输入一下命令

sudo apt-get update --fix-missing
下完后重启,再次输入下载命令

reboot
sudo apt-get install ubuntu-desktop
运行桌面环境

startx
桌面下载完成

2、开启VNC

为了能不连接HDMI就能在树莓派上进行图形化操作,我们需要安装vnc服务。vnc能将完整的窗口界面通过网络,传输到另一台计算机的屏幕上。

先通过SSH链接树莓派,更新软件源目录:

apt-get update
vnc服务有很多种选择,这里我选择的是vnc4server。安装vnc4server:

apt-get install vnc4server
等到安装完成后,启用vnc服务:

vnc4server
第一次启动vnc4server都需要输入密码,这个密码在后面用电脑连接需要用到。假如后面需要更改 VNC 连接密码,只需要输入 vncpassword 即可。开启服务后还会显示端口号

下载VNC viewer,下载链接

修改vnc配置文件:

vim ~/.vnc/xstartup
修改成以下配置

!/bin/sh

Uncomment the following two lines for normal desktop:

unset SESSION_MANAGER

exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb \(HOME/.Xresources xsetroot -solid grey vncconfig -iconic & x-terminal-emulator -geometry 80x24+10+10 -ls -title "\)VNCDESKTOP Desktop" &
x-window-manager &

gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
保存退出后,先退出原本运行中的vnc进程:

vncserver -kill :1
重新创建新进程:

vncserver :1
打开刚才下载的VNC

输入树莓派的IP及进程,IP+:1,连接后

设置VNC开机自启动,这样每次开机就不用启动一次VNC了

首先

sudo vim /etc/init.d/vnc4server
将下面的文字复制保存进去,有些地方要根据自己的情况修改

!/bin/sh

BEGIN INIT INFO

Provides: tightvncserver

Required-Start: $local_fs

Required-Stop: $local_fs

Default-Start: 2 3 4 5

Default-Stop: 0 1 6

Short-Description: Start/stop tightvncserver

END INIT INFO

More details see:

http://www.penguintutor.com/linux/tightvnc

Customize this entry

Set the USER variable to the name of the user to start tightvncserver under

export USER='ubuntu'
#上边要换成自己的用户名
### End customization required

eval cd ~$USER

case "$1" in
start)

su $USER -c '/usr/bin/vncserver -depth 16 -geometry 950x600 :1'
echo "Starting VNC server for $USER "
;;
stop)
# 950x600换成自己屏幕的分辨率
su $USER -c '/usr/bin/vncserver -kill :1'
echo "vncserver stopped"
;;
*)
echo "Usage: /etc/init.d/vncserver {start|stop}"
exit 1
;;
esac
exit 0
最后

sudo chmod 755 /etc/init.d/vnc4server
sudo update-rc.d vnc4server defaults

posted @ 2023-03-10 17:25  星苑  阅读(359)  评论(0)    收藏  举报