ubuntu 16.04/18.04/20.04/21.10配置远程桌面访问

远程桌面在 `Linux` 中一般使用 `VNC` ,下面我们总结一下 `ubuntu 16.04/18.04` 下的配置总结:

$ sudo apt-get update

# ubuntu 18.04/20.04 默认使用gdm3,导致VNC工作异常,需要切换到 lightdm 
# ubuntu 16.04 默认使用 lightdm 因此一般不需要调整
$ sudo apt install lightdm

# 配置切换到 lightdm
$ sudo dpkg-reconfigure gdm3

$ sudo apt install xserver-xorg-video-dummy

# 如果从 gdm3 切换到 lightdm 需要重启系统,否则不能正常工作
$ sudo reboot

$ sudo apt-get install x11vnc

# ubuntu 20.04
# sudo apt-get install net-tools

# 设置登录密码,如果不设置密码,会导致任意人都可以登录
$ sudo x11vnc -storepasswd /etc/x11vnc.pass

# 需要手工设置一下权限,默认设置的权限可能会导致其他用户无法正常读取
$ sudo chmod 755 /etc/x11vnc.pass

# '-rfbport' 参数指定监听端口,'-forever' 参数指定客户端断开后不要停止服务而是继续等待下一次的连接请求  '-rfbauth' 参数指定验证密码的存储文件
$ sudo x11vnc -auth guess -rfbauth /etc/x11vnc.pass -rfbport 5900 -forever -display :0

设置开机启动

$ sudo apt-get install vim

$ sudo vim /etc/systemd/system/x11vnc.service

里面内容如下:

[Unit]
Description=x11vnc (Remote access)
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -rfbauth /etc/x11vnc.pass -rfbport 5900 -forever -display :0
ExecStop=/bin/kill -TERM $MAINPID
ExecReload=/bin/kill -HUP $MAINPID
KillMode=control-group
Restart=on-failure

[Install]
WantedBy=graphical.target

配置 `systemd` 启用服务

$ sudo systemctl daemon-reload

$ sudo systemctl enable x11vnc

$ sudo systemctl start x11vnc

如果登录之后,只出现一个桌面背景,没有任何菜单,如下:

参考 Intel NUC(NUC6i3SYH)在不接显示器的情况下VNC不显示桌面(Ubuntu 18.04) 解决,网上搜索相关问题的时候可以使用关键词 HEADLESS X11 查找解决方案,其实就是不插入显示器的情况下,如何强制显卡渲染。

如果系统是ubuntu 21.10版本,则需要编辑

# ubuntu 21.10 版本配置文件 

$ sudo vim /etc/X11/xorg.conf

然后在文件尾部,增加如下配置:

Section "Device"
  Identifier  "Configured Video Device"
  Driver      "dummy"
EndSection

Section "Monitor"
  Identifier  "Configured Monitor"
  HorizSync 31.5-48.5
  VertRefresh 50-70
EndSection

Section "Screen"
  Identifier  "Default Screen"
  Monitor     "Configured Monitor"
  Device      "Configured Video Device"
  DefaultDepth 24
  SubSection "Display"
    Depth 24
    Modes "1920x1080"
  EndSubSection
EndSection

完成后,重启系统。

注意:如果系统上使用nvidia显卡,需要首先通过nvidia-xconfig生成默认配置,如果没有默认配置,会导致 nvidia-smi找不到显卡,一些使用显卡的计算任务或者机器学习框架会出现问题。

参考命令如下:

$ sudo nvidia-xconfig -a --virtual=1920x1200 

可能会生成类似如下配置内容:

# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 495.44

Section "ServerLayout"
    Identifier     "Default Layout"
    Screen      0  "Screen0"
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "NVIDIA GeForce RTX 3060"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    SubSection     "Display"
        Virtual     1920 1200
        Depth       24
    EndSubSection
EndSection

然后在配置文件的尾部增加

Section "Device"
  Identifier  "Configured Video Device"
  Driver      "dummy"
EndSection

Section "Monitor"
  Identifier  "Configured Monitor"
  HorizSync 31.5-48.5
  VertRefresh 50-70
EndSection

Section "Screen"
  Identifier  "Default Screen"
  Monitor     "Configured Monitor"
  Device      "Configured Video Device"
  DefaultDepth 24
  SubSection "Display"
    Depth    24
    Virtual  1920 1200
    Modes    "1920x1200"
  EndSubSection
EndSection

最后修改Section "ServerLayout"字段里的Screen 0为新增的屏幕(Section "Screen" 字段中的 Identifier定义的名字)。

修改参考如下:

Section "ServerLayout"
    Identifier     "Default Layout"
    Screen      0  "Default Screen"
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

修改后的完整内如如下:

# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 495.44

Section "ServerLayout"
    Identifier     "Default Layout"
    Screen      0  "Default Screen"
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "NVIDIA GeForce RTX 3060"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    SubSection     "Display"
        Virtual     1920 1200
        Depth       24
    EndSubSection
EndSection

Section "Device"
  Identifier  "Configured Video Device"
  Driver      "dummy"
EndSection

Section "Monitor"
  Identifier  "Configured Monitor"
  HorizSync 31.5-48.5
  VertRefresh 50-70
EndSection

Section "Screen"
  Identifier  "Default Screen"
  Monitor     "Configured Monitor"
  Device      "Configured Video Device"
  DefaultDepth 24
  SubSection "Display"
    Depth    24
    Virtual  1920 1200
    Modes    "1920x1200"
  EndSubSection
EndSection

尽管经过上面的设置,可以正确使用VNC,但是更推荐使用RDP协议,功能更丰富,性能更高,安全性更好。参考 VNC 还是 RDP? 云上的远程桌面究竟该如何选

参考链接


Chrome浏览器出现“由贵单位管理”原因及解决去除方法

最近有很多 `Chrome` 浏览器用户突然发现设置选项提示“`由贵单位管理`”,并且还可能在操作中心里弹出这个通知,或者在“下载”页面中出现“`您的浏览器由所属组织管理`”,或者在“关于 Google Chrome(G)”页面中出现“`您的浏览器受管理`”。

如果是企业用户遇到这个通知可能还能理解但不少个人用户也遇到这种情况,使用的并非谷歌浏览器企业版。

继续阅读Chrome浏览器出现“由贵单位管理”原因及解决去除方法

macOS上使用Openconnect代替Cisco Anyconnect

`OpenConnect` 是一个 `Cisco Anyconnect` 的替代品,具有开源、易获取、可靠等优点。而官方版本的 `Cisco Anyconnect` 配置较为繁琐,需要在管理界面同时部署多平台客户端才能支持多平台。相比之下 `OpenConnect` 在这点就具有优势,可以在官方版本无法跨平台时替代使用。

命令行模式:

$ brew install openconnect

# 用法示例如下 $url 服务器的域名 $username用户名认证时候的用户名
$ sudo openconnect $url --protocol=anyconnect --user $username

`GUI` 界面模式:

$ brew cask install openconnect-gui

使用起来是非常简单的。

注意:对于`OS X EI Caption`来说(Mac mini(Early 2009)已经不能升级系统了),由于`openconnect-gui`需要`QT 5.8`以上的版本,而`HomeBrew`已经不支持这个版本的系统,因此,安装的`openconnect-gui`之后,运行的时候进程会崩溃。

上面的情况,一般建议使用命令行版本进行操作。

参考链接


MAC修改主机名/计算机名

mac安装完成以后会默认将你的机器设成"longsky's Macbook Pro"之类的名字。这个本身看着就不爽,如果这台机器是别人先用你再用的话,就想把它改掉了。如果你想改计算机名的话,直接去"系统设置"->"共享"里改计算机名(Computer Name)就好了。这样大家在网络邻居里看到的你的名字就可以了。
对于大多数用户来说到这里就完事了。但是对于系统管理员来说,每次打开终端的时候发现还有一个"longsky's Macbook Pro"的东东在那里还是感觉很不爽。估计这个想改的人少,笔者费了九牛二虎之力才在mac的一个论坛的不起眼的小角落翻出来修改它的命令:

$ sudo scutil --set HostName longskys-MBP

继续阅读MAC修改主机名/计算机名

ubuntu 16.04.5升级到ubuntu 18.04启动时出现"No symbol table found."

`ubuntu 16.04.5` 升级到 `ubuntu 18.04.1` 启动时出现 "Error: no symbol table"

# 升级系统执行如下命令
$ sudo do-release-upgrade -d

重启之后,出现错误信息

No symbol table found. 
Press any key to continue...

不做任何操作,过几秒之后,能跳过。

解决方法如下:

$ sudo grub-install /dev/sda

$ sudo update-grub

$ sudo reboot

参考链接


ubuntu 16.04.5升级到ubuntu 18.04出现systemd-shim升级失败

`ubuntu 16.04.5` 升级到 `ubuntu 18.04.1` 出现 `systemd-shim` 升级失败,重启系统之后,继续执行软件升级,出现如下错误信息:

$ sudo apt-get dist-upgrade 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
正在计算更新... 完成
下列软件包将被【卸载】:
  systemd-shim
下列软件包将被升级:
  apache2 apache2-bin apache2-data apache2-utils libmspack0 linux-firmware
升级了 6 个软件包,新安装了 0 个软件包,要卸载 1 个软件包,有 0 个软件包未被升级。
有 1 个软件包没有被完全安装或卸载。
需要下载 0 B/72.5 MB 的归档。
解压缩后会消耗 4,250 kB 的额外空间。
您希望继续执行吗? [Y/n] 
(正在读取数据库 ... 系统当前共安装有 415046 个文件和目录。)
正在卸载 systemd-shim (9-1bzr4ubuntu1) ...
正在删除 systemd-shim 导致 /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service 转移到 /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service.systemd
dpkg-divert: 错误: 更改  /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service.systemd  文件名会覆盖  /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service,
  不允许此操作
dpkg: 处理软件包 systemd-shim (--remove)时出错:
 installed systemd-shim package post-removal script subprocess returned error exit status 2
在处理时有错误发生:
 systemd-shim
E: Sub-process /usr/bin/dpkg returned an error code (1)

如果语言是英文的,可能会出现如下信息:

$ sudo apt-get dist-upgrade 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be REMOVED:
  systemd-shim
The following packages will be upgraded:
  apache2 apache2-bin apache2-data apache2-utils libmspack0 linux-firmware
6 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0 B/72.5 MB of archives.
After this operation, 4,250 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
(Reading database ... 415046 files and directories currently installed.)
Removing systemd-shim (9-1bzr4ubuntu1) ...
Removing 'diversion of /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service to /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service.systemd by systemd-shim'
dpkg-divert: error: rename involves overwriting '/usr/share/dbus-1/system-services/org.freedesktop.systemd1.service' with
  different file '/usr/share/dbus-1/system-services/org.freedesktop.systemd1.service.systemd', not allowed
dpkg: error processing package systemd-shim (--remove):
 installed systemd-shim package post-removal script subprocess returned error exit status 2
Errors were encountered while processing:
 systemd-shim
E: Sub-process /usr/bin/dpkg returned an error code (1)

解决方案如下:

$ sudo mv /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service.bak

$ sudo apt-get dist-upgrade

$ sudo rm -rf /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service.bak

参考链接


尝试修复希捷固件门硬盘(SV35系列ST3000VX000)

最近家里的`NAS` 服务器上的希捷硬盘挂了,总寿命不超过 `1` 万小时,当时买硬盘的时候,记得是特意规避过希捷的 `STX000DM001` 这个版本的硬盘,这个版本的硬盘由于质量问题,基本上都会挂掉。  结果没想到,`ST3000VX000`不过是 `ST3000DM001` 的马甲而已。

中招,经过下面的修复之后,依旧没有办法修复,数据无法读取成功。尝试其他命令之后,整盘报废,`ST3000DM001` 系列硬盘完全没办法用,尽管关键数据都已经冗余备份,但是部分次要数据依旧丢失。

下面只是记录一下操作过程,没有实际意义。

希捷硬盘型号信息查询网站: https://apps1.seagate.com/downloads/request.html
继续阅读尝试修复希捷固件门硬盘(SV35系列ST3000VX000)