版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 (作者:张华 发表于:2019-04-14)
买了一款Intel compute stick core m3, 具有HDMI接口输出音频, 但如何使用手机临时地作为显示器及键盘鼠标控制它呢?
屏幕共享 - vnc & teamviewer & anydesk
windows上有一款叫spacedesk的软件, 电脑和手机上都安装它之后, 在同一个局域网可以很方便地从手机控制电脑棒.
Ubuntu上可以使用vnc, teamviewer, anydesk.
- ubuntu上安装VNC
# https://medium.com/@aldo_mx/simplest-way-to-configure-vnc-server-in-xubuntu-16-04-lts-and-newer-6c0b3ae21fe5
sudo apt-get install vino
gsettings list-recursively org.gnome.Vino
# some clients like TightVNC for Windows do not work with encryption anymore
# because older protocols like SSLv3 and TLSv1 have been deprecated.
# dconf-editor - ORG > GNOME > DESKTOP > REMOTE ACCESS
gsettings set org.gnome.Vino require-encryption false
# activate at startup, or set "Settings -> Sharing -> screen Sharing" in ubuntu
sudo cp /usr/share/applications/vino-server.desktop /etc/xdg/autostart/vino-server.desktop
# #enable "Application Autostart -> Desktop Sharing(Gnome Desktop Sharing Server)"
xfce4-session-settings
/usr/lib/vino/vino-server --sm-disable
vncviewer 192.168.99.124:5900 #but too slow
需注意两点:一是要设置require-encryption=false, 二是手机上使用realvnc client时不应该登陆,因为没用realvnc server,而是用的vino server
但是vino太慢了,改成vnc4server又是花屏的.
sudo apt -y install vnc4server
vncpasswd #not use sudo
#vncserver -kill :0
#taken because of /tmp/.X11-unix/X0
sudo rm /tmp/.X11-unix/X0 && sudo rm /tmp/.X0-lock
vncserver -geometry 1280x800 -alwaysshared :0
所以最后使用xrdp
sudo apt -y install xrdp
cat /etc/xrdp/xrdp.ini
sudo systemctl status xrdp
sudo adduser xrdp ssl-cert
#sudo ufw allow from 192.168.99.0/24 to any port 3389
#sudo ufw allow 3389
use Remmina as rdp client
20230321更新 - 今天按上面的方法安装xrdp,但通过remmina却连不上。chatgpt说"如果您仍然无法连接,请确保目标 Ubuntu 主机已经启用了 Remote Desktop 功能。您可以在 Settings -> Sharing -> Screen Sharing 中启用该功能。另外,您还需要为远程用户设置密码,您可以在 Settings -> Users 中设置密码。",但试了也不行。后来重启机器之后才可以.
- 安装使用anydesk使用屏幕, 鼠标, 键盘. (但没法用本地摄像头)
wget https://download.anydesk.com/linux/anydesk_4.0.1-1_amd64.deb
sudo dpkg -i anydesk_4.0.1-1_amd64.deb
sudo apt --fix-broken install
sudo dpkg -i anydesk_4.0.1-1_amd64.deb
echo 'password' |sudo anydesk --set-password
sudo systemctl enable anydesk.service
最后, 设置anydesk, 设置允许随时连接查询, 并设置密码, 禁用掉声音传输.
但又遇到一个问题, 在笔记本上测试anydesk似乎没有问题. 但移到电脑棒上后, 电脑棒启动后经常无故死机. (无故死机的问题找到了, 一次是因为电源没插好接触不良, 另一次是应用了平时给手机充电的Type-A USB输出的充电器, 应该使用自带的APD亚源科技的Type-C输出口的充电器(输出则是5.2V 2.2A(Type-C对机身)、5V 0.9A(对两个Type-A),这个问题真难查). 但仍然遇到一个问题 (手机上的anydesk发起连接时报: 连接已终止,. 状态: result_invalid_state,暂不清楚原因)
- 切换为teamviewer, 也是遇到类似问题, 曾经成功过, 但之后手机上的teamviewer就一起报: teamviewer正在启动, 请稍候. (该问题原因已找到, 因为墙,用4G网络可以, 见: https://github.com/ywb94/openwrt-ssr/issues/31 及 https://zvv.me/z/1366.html )
还存在一个问题: **如果电脑棒不通过HDMI接口接一个显示器, 电脑棒重启之后通过远程桌面连接过去看到的是一屏黑色. 那是因为Linux服务器一般是不接显示器的,用ssh等文字界面连接管理即可, 可是有些软件需要GUI管理,若不接显示器,xwindows是默认无法启动的,从而导致vnc server连接失败, 可配置一块fake显示器解决:
# https://askubuntu.com/questions/453109/add-fake-display-when-no-monitor-is-plugged-in
sudo apt-get install xserver-xorg-video-dummy xfce4 chromium
sudo bash -c 'cat > /usr/share/X11/xorg.conf.d/xorg.conf' <<EOF
Section "Device"Identifier "Configured Video Device"Driver "dummy"
EndSectionSection "Monitor"Identifier "Configured Monitor"HorizSync 31.5-48.5VertRefresh 50-70
EndSectionSection "Screen"Identifier "Default Screen"Monitor "Configured Monitor"Device "Configured Video Device"DefaultDepth 24SubSection "Display"Depth 24Modes "1024x800"EndSubSection
EndSection
EOF
sudo reboot
但是使用上述的软件模拟的显示器, 会造成即使接了真显示器, 还是用得虚拟的, 所以不方便啊. 网上有硬件的Dummy HDMI可用.
kdeconnect
kdeconnect可以用来在ubuntu与androd之间双向传输数据, 例如电脑使用手机的键盘鼠标, 电脑与手机相互传输数据, 手机上的短信通知发给电脑显示.
直接在电脑与手机上安装kdeconnect即可使用.
sudo apt install kdeconnect
但kdeconnectd进程 (/etc/xdg/autostart/kdeconnectd.desktop)在ubuntu未登录之前是不会启动的, 所以禁用掉电脑棒的密码登录设置它为自动登录即可.
gsconnect gshell extension
gsconnect与kdeconnect是类似的东西, 它不依赖kde的一些包, 但它依赖Gnome desk与chrome, 电脑棒启动后没有自动启动chrome的话用不了. 所以实际我用的还是kdeconnect, 但这里记录使用gsconnect的过程.
- 安装gnome-shell-extension与chrome-gnome-shell
gnome-shell --version
sudo apt install gnome-shell-extensions
sudo apt install chrome-gnome-shell
离个题, 例如想显示各个不同时区的team member的上班时间的话, 可以添加~/people.json将每个人的时区按下列格式添加进去即可.
vim ~/people.json
[
{"name": "your name","github": "your lauchpd id", "city": "Beijing","tz": "Asia/Shanghai"
}
]
- 访问这个网址https://extensions.gnome.org/extension/1319/gsconnect/ 方便地安装gsconnect即可 (注意: 如果出错, 多半是因为没有在chrome里访问 chrome://extensions/ 将GNOME Shell integration打开的原因).
- 手机上在play里搜索安装KDE Connect, 并打开它, 和gsconnect为pair配对.
- 还可以支持电脑上Nautilus来mount手机上的文件
sudo apt install python-nautilus gir1.2-nautilus-3.0 sshfs
# then send file to Android by first open the nautilus then right click one file "Send to Mobile Device -> Nokia"
附录 - 让vnc开机自动运行
刚开始打算把开vnc的脚本放到rc.local里,但不work, 因为运行vnc是需要home目录的
/usr/bin/vncserver -kill :4
/usr/bin/vncserver :4 -localhost no -geometry 1024x768
/usr/bin/ssh -o ConnectTimeout=5 -o ServerAliveInterval=50 -fNR 43301:localhost:5904 xxx-jump
sudo bash -c 'cat >/etc/systemd/system/rc-local.service' <<EOF
[Unit]Description=/etc/rc.local CompatibilityConditionPathExists=/etc/rc.local
[Service]Type=forkingExecStart=/etc/rc.local startTimeoutSec=0StandardOutput=ttyRemainAfterExit=yesSysVStartPriority=99
[Install]WantedBy=multi-user.target
EOF
printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local
sudo chmod +x /etc/rc.local
sudo systemctl enable rc-local
sudo systemctl restart rc-local.service
sudo systemctl status rc-local.service
所以最后搞成下面的:
sudo bash -c 'cat >/etc/init.d/vncserver' <<EOF
#!/bin/sh -ePATH="$PATH:/usr/X11R6/bin/"# The Username:Group that will run VNC
export USER="zhhuabj"
#${RUNAS}# The display that VNC will use
DISPLAY="4"# Color depth (between 8 and 32)
DEPTH="16"# The Desktop geometry to use.
#GEOMETRY="<WIDTH>x<HEIGHT>"
GEOMETRY="1024x768"# The name that the VNC Desktop will have.
NAME="zhhuabj-vnc"OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}". /lib/lsb/init-functionscase "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;stop)
log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;restart)
$0 stop
$0 start
;;
esacexit 0
EOF
sudo chmod +x /etc/init.d/vncserver
sudo update-rc.d vncserver defaults
sudo /etc/init.d/vncserver start
vncserver
sudo apt install vnc4server xfce4 xfce4-goodies -y
vncpasswd
sudo bash -c 'cat > ~/.vnc/xstartup' << EOF
#!/bin/bash
startxfce4 &
EOF
sudo chmod +x ~/.vnc/xstartup
/usr/bin/vncserver -kill :1
/usr/bin/vncserver :1 -geometry 1024x768
sudo ufw allow from any to any port 5901 proto tcp
20200818更新
使用todesk - https://www.todesk.com/download.html
20230419更新 - rustdesk
可以使用rustdesk,下面是自定义国内rustdesk服务器的步骤:
# hhbr is relay service, while hbbs is registration service
wget https://github.com/rustdesk/rustdesk-server/releases/download/1.1.7-4/rustdesk-server-hbbr_1.1.7_amd64.deb
wget https://github.com/rustdesk/rustdesk-server/releases/download/1.1.7-4/rustdesk-server-hbbs_1.1.7_amd64.deb
sudo dpkg -i rustdesk-server-hbb*
sudo systemctl cat rustdesk-hbbs.service |grep WorkingDirectory
# secret key
cat /var/lib/rustdesk-server/id_ed25519.pub
# TCP(21115, 21116, 21117, 21118, 21119) UDP(21116)
20230518 更新
一直用xrdp好好的,忽然就不行了。后来debug后发现是gdm3的loop login老毛病又回来了。所以只好放弃xrdp.
用gnome自带的rdp(gnome-remote-desktop)吧,登录进去了,但是就一个桌面,看不到开始菜单。
从rdp换成vnc吧,还是花屏老毛病,放弃.
本来换成anydesk了的,但今天也是忽然点了之后一块白板。但是现在也没选择了,只能继续试anydesk, 发现重新安装一下白板消失了。 通过’sudo systemctl status anydesk '找到了之前白板的原因是因为需要安装libcanberra-gtk-module这个包.
另外, 下次再继续发生remote desktop的问题,那直接改用’ssh -X’了,记得添加’export XAUTHORITY=$HOME/.Xauthority’来支持snap应用
20230530 - 将iphone投屏到ubuntu
现在一些app总是只有手机版,没有电脑版,天天对着手机小屏幕容易坏眼睛,有必要将iphone投屏到ubuntu有种方式:
1, airdroid cast, iphone上安装airdroid cast, ubuntu从这个网页访问:https://webcast.airdroid.com/?lang=en#/ ,是基于浏览器,并且声音还在手机上。
2, UxPlay, ubuntu上安装如下,iphone上正常投屏连接即可。声音在ubuntu上.
sudo apt install libplist-dev libavahi-compat-libdnssd-dev -y
sudo apt install libgstreamermm-1.0-dev gstreamer1.0-plugins-bad gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-libav -y
git clone https://github.com/antimof/UxPlay.git
cd UxPlay
mkdir build & cd build
cmake ..
make
./uxplay#注意将将XDG_RUNTIME_DIR与DISPLAY改成合适的值,在终端上通过echo $DISPLAY可找到合适的值
$ cat /etc/systemd/system/uxplay.service
[Unit]
Description=uxplay
Wants=network-online.target
After=network.target[Service]
Type=simple
User=hua
Group=hua
Environment="XDG_RUNTIME_DIR=/run/user/1000" "DISPLAY=:1"
ExecStart=/bak/soft/UxPlay/build/uxplay[Install]
WantedBy=multi-user.target