Farseerfc的小窩 - chrome//farseerfc.me/2015-02-13T20:39:00+09:00archlinux 上用 chrome 實現 透明計算 遠程登錄2015-02-13T20:39:00+09:002015-02-13T20:39:00+09:00farseerfctag:farseerfc.me,2015-02-13:/arch-chrome-remote-desktop.html
<p><a class="reference external" href="http://news.sciencenet.cn/htmlnews/2015/1/311393.shtm">透明計算</a>
具體是什麼,因爲他們沒有公開技術細節所以我並不知道,只是看
<a class="reference external" href="http://v.qq.com/page/h/v/q/h0145ebh1vq.html">公開出來的演示視頻</a>
,感覺似乎只要能從手機上遠程登錄系統桌面,就能算是透明計算了。
如果透明計算真是這個意思,那麼我似乎已經用着這個技術很多年了嘛。</p>
<p>Xorg 上常用的遠程桌面工具有很多,基於 VNC 協議的、基於NX的和基於 RDP 協議的都能找到,
直接 ssh X forwarding 效果也不錯。只是這些方案的一個 <strong>不太易用</strong> 的地方在於,需要
通過 ip 訪問到遠程的電腦,所以在跨越 NAT 之類的情況下不太容易使用。</p>
<p>於是今天介紹一個使用方便設置也簡單的方法: 通過 chrome-remote-desktop 在 archlinux
上使用遠程桌面。這個方案的優勢在於,藉助 Google 的雲端服務器(內部貌似是XMPP協議下的握手)
方便地實現了 NAT 穿透,無論什麼網絡環境基本都能使用。當然,要支持遠程登錄,
位於遠端的登錄的計算機必須一直開着 …</p>
<p><a class="reference external" href="http://news.sciencenet.cn/htmlnews/2015/1/311393.shtm">透明計算</a>
具體是什麼,因爲他們沒有公開技術細節所以我並不知道,只是看
<a class="reference external" href="http://v.qq.com/page/h/v/q/h0145ebh1vq.html">公開出來的演示視頻</a>
,感覺似乎只要能從手機上遠程登錄系統桌面,就能算是透明計算了。
如果透明計算真是這個意思,那麼我似乎已經用着這個技術很多年了嘛。</p>
<p>Xorg 上常用的遠程桌面工具有很多,基於 VNC 協議的、基於NX的和基於 RDP 協議的都能找到,
直接 ssh X forwarding 效果也不錯。只是這些方案的一個 <strong>不太易用</strong> 的地方在於,需要
通過 ip 訪問到遠程的電腦,所以在跨越 NAT 之類的情況下不太容易使用。</p>
<p>於是今天介紹一個使用方便設置也簡單的方法: 通過 chrome-remote-desktop 在 archlinux
上使用遠程桌面。這個方案的優勢在於,藉助 Google 的雲端服務器(內部貌似是XMPP協議下的握手)
方便地實現了 NAT 穿透,無論什麼網絡環境基本都能使用。當然,要支持遠程登錄,
位於遠端的登錄的計算機必須一直開着 Chrome Remote Desktop 的後臺服務。</p>
<div class="panel panel-default">
<div class="panel-heading">
Chrome Remote Desktop 插件</div>
<div class="panel-body">
<img alt="Chrome Remote Desktop 插件" class="img-responsive" src="//farseerfc.me/images/chrome-remote-desktop-plugin.png"/>
</div>
</div>
<div class="section" id="chrome-remote-desktop">
<h2><a class="toc-backref" href="#id5">Chrome Remote Desktop 的客戶端</a></h2>
<p>雖然可能有很多人不知道,不過 Chrome 內包括遠程桌面的功能很久了。只是這個功能的界面默認
沒有提供界面,要使用它需要安裝 Google 官方出品的
<a class="reference external" href="https://chrome.google.com/webstore/detail/chrome-remote-desktop/gbchcmhmhahfdphkhkmpfmihenigjmpp">remote-desktop 插件</a> 。
裝好之後遠程桌面的客戶端就準備好,可以用來遠程訪問別的計算機桌面了(無論是 Windows/OS X
還是 Linux 都支持)。並且不光可以自己遠程訪問自己賬戶的桌面,還可以遠程協助朋友的桌面。</p>
</div>
<div class="section" id="archlinux">
<h2><a class="toc-backref" href="#id6">Archlinux 上設置遠程登錄的服務器</a></h2>
<p>有了客戶端之後還要設置一下纔能讓桌面作爲遠程登錄的服務器。Windows 和 OS X 上 Chrome
會自動下載需要的安裝包,無腦下一步就能裝好了。Linux上由於發行版衆多,桌面配置各異,
所以需要一點手動配置。官方的設置步驟記載在 <a class="reference external" href="https://support.google.com/chrome/answer/1649523">這裏</a>
其中給出了 debian 用的二進制包和 Ubuntu 12.10 上的設置方式,以下設置是參考官方步驟。</p>
<p>首先要安裝 chrome-remote-desktop 這個包,這個包實際上對應了 Windows/OS X 上用安裝程序
安裝的 Remote Desktop Host Controller。 archlinux 上開啓了
<a class="reference external" href="https://github.com/archlinuxcn/repo">[archlinuxcn]</a>
倉庫的話,可以直接安裝打好的包。或者可以從
<a class="reference external" href="https://aur.archlinux.org/packages/chrome-remote-desktop/">AUR</a> 裝。</p>
<pre><span class="code-line">$ pacman -Ss chrome-remote-desktop<br/><span style="color:purple;font-weight:bold;">archlinuxcn/</span><span style="font-weight:bold;">chrome-remote-desktop </span><span style="color:green;font-weight:bold;">40.0.2214.44-1</span><br/>Allows you to securely access your computer over the Internet through Chrome.</span></pre><p>裝好之後從會說這麼一段話:</p>
<blockquote>
<p>groupadd:无效的组 ID “chrome-remote-desktop”</p>
<p>Please create ~/.config/chrome-remote-desktop folder manually, if it doesn't exist, or else you can't use CRD.
The needed files are created by the Chrome app, inside the chrome-remote-desktop folder, after Enabling Remote Connections.
To {enable,start} the service use systemctl --user {enable,start} chrome-remote-desktop</p>
<p>You may need to create a ~/.chrome-remote-desktop-session file with commands to start your session</p>
<p>Go to <a class="reference external" href="https://support.google.com/chrome/answer/1649523">https://support.google.com/chrome/answer/1649523</a> for more information.</p>
</blockquote>
<p>那句報錯是 AUR 裏打的包還沒跟上上游 Google 的更改導致的錯誤,
首先我們需要把遠程登錄的用戶添加入 chrome-remote-desktop 這個用戶組裏。
新版本的 chrome remote desktop 提供了一個命令做這個事情,所以執行以下命令就可以了:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="gp">$</span> /opt/google/chrome-remote-desktop/chrome-remote-desktop --add-user</span>
</pre></div>
<p>然後我們需要手動創建 <code class="code">
~/.config/chrome-remote-desktop</code>
這個文件夾,內容是空的
就好了,隨後 chrome 會往這裏面放 <code class="code">
host#.json</code>
文件用於身份驗證。</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="gp">$</span> mkdir ~/.config/chrome-remote-desktop</span>
</pre></div>
<p>然後我們要創建一個 shell 腳本 <code class="code">
~/.chrome-remote-desktop-session</code>
,這是遠程
登錄時的 .xinitrc ,內容麼就是啓動你想在遠程登錄時用的桌面環境。
這裏可以指定一個和你正在登錄的 WM/DE 不同的桌面,比如我啓動 xfce4:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="gp">$</span> cat ~/.chrome-remote-desktop-session</span>
<span class="code-line"><span class="gp">#</span>!/bin/bash</span>
<span class="code-line"><span class="go">startxfce4</span></span>
<span class="code-line"><span class="gp">$</span> chmod <span class="m">755</span> .chrome-remote-desktop-session</span>
</pre></div>
<p>接下來需要從 Chrome 的插件裏啓用遠程桌面。打開 Chrome 的 Remote Desktop 插件,這時
應該可以看到一個「啓用遠程鏈接」的按鈕。</p>
<div class="figure">
<img alt="Chrome Remote Desktop 插件中「啓用遠程鏈接」的按鈕" class="img-responsive" src="//farseerfc.me/images/chrome-remote-desktop-enable-button.png"/>
<p class="caption">Chrome Remote Desktop 插件中「啓用遠程鏈接」的按鈕</p>
</div>
<div class="alert alert-warning compound">
<p>在撰寫本文的時候, Archlinux 官方源裏的 chromium 的版本和 aur/google-chrome
的版本尚且還是 40.0.2214.111 ,而 Chrome Web Store 中提供的 Chrome Remote
Desktop 的插件的版本是 41.0.2272.41 。雖然通常並不要求兩者版本一致,不過貌似最近
Chrome 內部的 Remoting 功能更改了 API 導致可能出問題。如果你找不到
「啓用遠程鏈接」的按鈕,請嘗試一下新版本的 Chrome 比如 google-chrome-dev 。
在這一步啓用之後,老版本的 chrome 應該也就能使用遠程桌面了。</p>
</div>
<div class="alert alert-warning compound">
<p>在32位的 Linux 版本上,最近更新的 Chrome Remote Desktop 插件可能無法正確識別 Host
的版本,具體 <a class="alert-link reference external" href="https://code.google.com/p/chromium/issues/detail?id=332930">參考這個 bug</a> 。</p>
</div>
<p>點擊「啓用遠程鏈接」,設定一個 PIN 密碼(不需要很複雜,這裏首先有 Google 帳號驗證保證只有
你纔能訪問),然後就能看到這套電腦的 hostname 出現在「我的電腦」列表裏。</p>
<div class="figure">
<img alt="啓用遠程鏈接之後的樣子" class="img-responsive" src="//farseerfc.me/images/chrome-remote-desktop-after-enabled.png"/>
<p class="caption">啓用遠程鏈接之後的樣子</p>
</div>
<p>同時,啓用了遠程鏈接之後,可以在剛剛創建的 ~/.config/chrome-remote-desktop
文件夾中找到記錄了驗證信息的文件。</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="gp">$</span> ls .config/chrome-remote-desktop</span>
<span class="code-line"><span class="go">chrome-profile host#8cfe7ecfd6bb17955c1ea22f77d0d800.json pulseaudio#8cfe7ecfd6</span></span>
</pre></div>
<p>然後就可以啓動對應的 systemd 用戶服務了,如果想自動啓動服務要記得 <code class="code">
systemctl --user enable</code>
:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="gp">$</span> systemctl --user start chrome-remote-desktop.service</span>
</pre></div>
<p>如果上面的設置一切正常,就可以看到 chrome-remote-desktop 啓動了另外一個 Xorg 執行你
剛剛指定的桌面環境:</p>
<div class="figure">
<img alt="htop 中看到的 chrome-remote-desktop 啓動的另外一個 Xorg" class="img-responsive" src="//farseerfc.me/images/chrome-remote-desktop-htop.png"/>
<p class="caption">htop 中看到的 chrome-remote-desktop 啓動的另外一個 Xorg</p>
</div>
<p>然後就可以試着通過 Remote Desktop 插件登錄到這個新開的 Xorg 了:</p>
<div class="figure">
<img alt="「遠程」登錄到新的 XFCE4" class="img-responsive" src="//farseerfc.me/images/chrome-remote-desktop-xfce4.png"/>
<p class="caption">「遠程」登錄到新的 XFCE4</p>
</div>
</div>
<div class="section" id="linux-chrome-windows-os-x">
<h2><a class="toc-backref" href="#id7">Linux 版本的 Chrome遠程桌面 和 Windows/ OS X 上的區別</a></h2>
<p>通過上面的設置步驟也可以看出,Linux版本的遠程桌面會在後臺開一個獨立的 X 會話,而不能
復用現在已有的 X 會話。對遠程登錄的用法而言這還能接受,對遠程協助的功能而言有點問題,
因爲正在使用的人不能觀察協助者做了什麼,協助者也不能繼續請求協助的人的操作。</p>
<p>當然目前 Chrome 遠程桌面的 Linux Host Controller 還只是 beta 版本,官方只測試支持
Ubuntu 12.04 和 12.10 (14.04之後似乎有
<a class="reference external" href="https://code.google.com/p/chromium/issues/detail?id=366432">Bug</a>
),所以不能要求太多。希望以後能改善吧。</p>
</div>
<div class="section" id="bonus">
<h2><a class="toc-backref" href="#id8">Bonus: 手機遠程登錄</a></h2>
<div class="panel panel-default">
<div class="panel-heading">
手機上的 Chrome 遠程桌面 App</div>
<div class="panel-body">
<img alt="手機上的 Chrome 遠程桌面 App" class="img-responsive" src="//farseerfc.me/images/chrome-remote-desktop-android.png"/>
</div>
</div>
<p>通過上面的設置就可以從任何一個 Chrome 遠程桌面客戶端登錄剛剛設置的這臺電腦了。
因爲 Chrome 在三大桌面系統 Windows / OS X / Linux 上都有,所以應該能覆蓋大多數桌面
系統了。</p>
<p>除了桌面的 Chrome 之外還有一個客戶端是 Android 上的
<a class="reference external" href="https://play.google.com/store/apps/details?id=com.google.chromeremotedesktop">Chrome 遠程桌面 App</a> 經過上面的設置之後,從這個 App 也能看到並登錄:</p>
<div class="figure">
<img alt="手機遠程登錄" class="img-responsive" src="//farseerfc.me/images/chrome-remote-desktop-android-logined.png"/>
<p class="caption">手機遠程登錄</p>
</div>
<p>好啦,開始享受國家自然科學一等獎的透明計算技術吧!</p>
</div>