一分钟搞定树莓派远程桌面

安装xrdp

打开树莓派终端,输入 sudoapt-get install xrdp ,等待xrdp安装完成

执行vncserver指令,(下面是执行结果)我们可以看到监听端口为 172.20.11.37:1 。

root@raspberrypi:~# vncserver
VNC(R) Server 6.4.0 (r39899) ARMv6 (Dec 7 2018 12:34:40)
Copyright (C) 2002-2018 RealVNC Ltd.
RealVNC and VNC are trademarks of RealVNC Ltd and are protected by trademark
registrations and/or pending trademark applications in the European Union,
United States of America and other jurisdictions.
Protected by UK patent 2481870; US patent 8760366; EU patent 2652951.
See https://www.realvnc.com for information on VNC.
For third party acknowledgements see:
https://www.realvnc.com/docs/6/foss.html
OS: Raspbian GNU/Linux 9, Linux 4.14.98, armv7l

Generating private key... done
xauth:  file /root/.Xauthority does not exist
On some distributions (in particular Red Hat), you may get a better experience
by running vncserver-virtual in conjunction with the system Xorg server, rather
than the old version built-in to Xvnc. More desktop environments and
applications will likely be compatible. For more information on this alternative
implementation, please see: https://www.realvnc.com/doclink/kb-546

Running applications in /etc/vnc/xstartup

VNC Server catchphrase: "Convert indigo Jessica. Salt pure postal."
             signature: 1a-03-2c-91-75-3e-30-5d

Log file is /root/.vnc/raspberrypi:1.log
New desktop is raspberrypi:1 (172.20.11.37:1)

安装使用VNC Viewer登录远程主机

在Windows系统上下载安装 VNC Viewer v6.19.715 ,在箭头位置输入上面的 ‘’IP+端口 ‘’按回车输入你的远程主机的账号密码登录即可,如下图
一分钟搞定树莓派远程桌面_第1张图片
登录成功。
一分钟搞定树莓派远程桌面_第2张图片

下面是配置VNC的开机自启

修改vnc密码:vncpasswd [登录用]

首先新建服务文件

sudo nano /etc/init.d/vncserver

然后 复制下面的内容 右键粘贴进去

#!/bin/sh
### BEGIN INIT INFO
# Provides:          vncserver
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop vncserver
### END INIT INFO
 
# More details see:
# http://www.penguintutor.com/linux/vnc
 
### Customize this entry
# Set the USER variable to the name of the user to start vncserver under
export USER='pi'       #登录用户名
### End customization required
 
eval cd ~$USER
 
case "$1" in
  start)
    # 启动命令行。此处自定义分辨率、控制台号码或其它参数。
    su $USER -c '/usr/bin/vncserver -depth 16 -geometry 1024x768 :1'
    echo "Starting VNC server for $USER "
    ;;
  stop)
    # 终止命令行。此处控制台号码与启动一致。
    su $USER -c '/usr/bin/vncserver -kill :1'
    echo "vncserver stopped"
    ;;
  *)
    echo "Usage: /etc/init.d/vncserver {start|stop}"
    exit 1
    ;;
esac
exit 0

然后 Ctrl+O 回车 保存

然后 Ctrl+X退出文本编辑器

然后 修改权限

sudo chmod 777 /etc/init.d/vncserver

然后 添加开机启动项

sudo update-rc.d vncserver defaults

最后 重启树莓派

sudo reboot

如果不出意外 树莓派开机后 就可以连接VNC了

转自树莓派3B远程VNC的设置(包括开机启动)

这样启动改脚本用service 命令就可以

sudo service vncserver start   #启动

sudo service vncserver stop    #停止

你可能感兴趣的:(❤)