2013年8月24日 星期六

Secure Shell 的 X11 Forwarding

SSH (Secure Shell) 的 X11 Forwarding 提供了一個很方便的功能,使用者可以從 A 電腦經由 SSH 連線到執行 Linux 的 B 電腦,然後利用 X11 Forwarding 將 B 電腦上的應用程式 GUI 畫面傳到 A 電腦。這是因為 X 視窗採用了 X server 及 X client 的架構。也就是,當我們在 A 電腦執行了 X server,而在 B 電腦執行 X client 時,X client 的 UI 畫面就會在 A 電腦上呈現了。

以 PuTTY 為例,在建立 SSH 連線時,先在選項設定裡將 X11 Forwarding 啟用就可以了。

這樣,就能將遠端執行的程式畫面傳回來了。例如,我在遠端執行了 virt-manager 這支程式,但它的畫面會顯示在執行 PuTTY 程式的這一端 (本地端)。

這裡,我的本地端使用的是 Linux Mint 這個系統,遠端則是 Debian GNU/Linux 系統。所以,只要單純在建立 SSH 連線啟用 X11 Forwarding,就可以在 Debian GNU/Linux 上執行任何視窗程式,畫面也會顯示在 Linux Mint 這端。

那麼,如果我不用 PuTTY 這個工具程式呢?在 Linux 裡有一個 ssh 指令,怎麼用它來使用 X11 Forwarding 呢?首先來看一下 ssh 這支工具程式的 manpage:

-X      Enables X11 forwarding.  This can also be specified on a per-host
        basis in a configuration file.

        X11 forwarding should be enabled with caution.  Users with the
        ability to bypass file permissions on the remote host (for the
        user's X authorization database) can access the local X11 display
        through the forwarded connection.  An attacker may then be able
        to perform activities such as keystroke monitoring.

        For this reason, X11 forwarding is subjected to X11 SECURITY
        extension restrictions by default.  Please refer to the ssh -Y
        option and the ForwardX11Trusted directive in ssh_config(5) for
        more information.

-Y      Enables trusted X11 forwarding.  Trusted X11 forwardings are not
        subjected to the X11 SECURITY extension controls.

這很容易使用,在終端程式使用 ssh 指令建立與遠端的 SSH 連線時,只要執行下面的指令即可 (這裡假設遠端的 IP 為 192.168.1.101):

$ ssh -l 你的帳號 -X 192.168.1.101

或

$ ssh -l 你的帳號 -Y 192.168.1.101

那,如果我的本地端是 Windows,怎麼辦呢?在之前,我介紹過 Xming 這個軟體,在 Windows 端安裝 Xming 後,再用 PuTTY 登入遠端的 Linux 就可以了。

在 Windows 可以使用的 X server 軟體,除了 Xming 之後,還有需要付費購買授權的 X-Deep/32、X-Win32、Xmanager 等。

而支援 SSH 的工具軟體,除了 PuTTY 之外,也還有需要付費購買授權的 SecureCRT、Xshell 等。其中,Xshell 提供了 Free for Home/School 的選擇。此外,SecureCRT 和 Xshell 更支援了 Zmodem 這個傳輸協定,相當方便。

例如下圖就是在 Windows 8.1 裡,使用 Xshell 這個工具程式登入遠端的 Debian GNU/Linux,然後將執行的 virt-manager 畫面傳回到 Windows 8.1 端。

2013年8月22日 星期四

phpMyAdmin 的設定

將下載回來的 phpMyAdmin 壓縮檔解開,並搬移到 /var/www 目錄後,將 config.sample.inc.php 複製成 config.inc.php。

接著,編輯 config.inc.php,找到這一行:

$cfg['Servers'][$i]['auth_type'] = 'cookie';

將它修改如下:

$cfg['Servers'][$i]['auth_type'] = 'http';

這是最基本的設定。

不過,當登入 phpMyAdmin 後,卻會發現在畫面下方出現如圖示的訊息:

雖然,這並不影響 phpMyAdmin 的操作,但每次看到這個訊息畫面,也總是覺得不開心。

要修正這點並不是很難,在剛才畫面的最末端就有提示了。

首先,建立一個資料庫,同時建立一個能完整存取這個資料庫的使用者。這裡,我將資料庫和使用者都命名為 phpmyadmin。

接著,在 phpMyAdmin 的目錄裡,找到 examples/create_tables.sql 這個檔案,將它匯入剛才建立的資料庫。

這個步驟一樣可以在 phpMyAdmin 管理介面裡完成。不過,由於我的 MariaDB 安裝在 Debian GNU/Linux 端,而我此時在 Windows 7 遠端操作 phpMyAdmin,所以我改成在 SSH 連線裡,以指令的方式操作:

$ cd phpmyadmin/examples/
$ mysql -uphpmyadmin -p你的密碼 phpmyadmin < create_tables.sql

接著,再修改 phpMyAdmin 的 config.inc.php,去掉以下區塊的註解:

/*
 * phpMyAdmin configuration storage settings.
 */

/* User used to manipulate with storage */
// $cfg['Servers'][$i]['controlhost'] = '';
$cfg['Servers'][$i]['controluser'] = 'phpmyadmin';
$cfg['Servers'][$i]['controlpass'] = '你的密碼';

/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
/* Contrib / Swekey authentication */
// $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';

接著,重新啟動 Apache,並重新登入 phpMyAdmin 管理介面,就不會再看到剛才的錯誤訊息了。

2013年8月21日 星期三

在 Debian 及 Linux Mint 上安裝 Apache + PHP + MariaDB

之前在 Debian 裡試裝了 Apache 及 PostgreSQL,也安裝了 WordPress 試用了一陣子,同時也簡單記錄了 "在 Debian 上安裝 Apache + PHP + PostgreSQL" 及 "如何安裝 WordPress?" 這兩篇文章。

這陣子因為還計畫試用一些其它的架站套件,因此也就繼續在 Debian 及 Linux Mint 裡安裝了 MariaDB,這篇是簡易的記錄。

目前 MariaDB 尚未收到 Debian 7 及 Linux Mint 15 的套件庫裡,所以必須從 MariaDB 的網站取得安裝程式。

在 MariaDB 的網站的下載頁面,選擇使用 repository configuration tool,依據說明選擇 Linux Distribution、版本及套件庫來源。

在 Debian 7 安裝 MariaDB 5.5:

$ sudo apt-get install python-software-properties
$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
$ sudo add-apt-repository 'deb http://download.nus.edu.sg/mirror/mariadb/repo/5.5/debian wheezy main'
$ sudo apt-get update
$ sudo apt-get install mariadb-server

在 Linux Mint 15 安裝 MariaDB 5.5:

首先,建立 /etc/apt/sources.list.d/mariadb.list 這個檔案,並加入以下內容:

# MariaDB 5.5 repository list - created 2013-08-16 01:23 UTC
# http://mariadb.org/mariadb/repositories/
deb http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/5.5/ubuntu raring main
deb-src http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/5.5/ubuntu raring main

接著,執行以下的指令:

$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo apt-get install mariadb-server

安裝 Apache 與 PHP

$ sudo apt-get install apache2 php5 php5-mysql libapache2-mod-php5filter

基本上,安裝完這些套件就可以用了。

此外,建議再安裝幾個與 PHP 相關的套件:

$ sudo apt-get install php5-curl php5-gd php5-gmp php5-imagick php5-json php5-mcrypt php5-xdebug php5-xmlrpc

然後在 /var/www 路徑下編寫一個 info.php 檔,內容如下:

<?php phpinfo(); ?>

用瀏覽器開啟 http://localhost/info.php 查看 PHP 是否順利安裝。

安裝 phpMyAdmin

到 http://www.phpmyadmin.net/ 下載最新版的 phpMyAdmin,將它解壓縮到 /var/www 目錄後,並修改屬性權限裡的使用者為 www-data,然後將 config.sample.inc.php 複製成 config.inc.php。

接著,編輯 config.inc.php,找到這一行:

$cfg['Servers'][$i]['auth_type'] = 'cookie';

將它修改如下:

$cfg['Servers'][$i]['auth_type'] = 'http';

這是最基本的設定,其它設定請自行參閱 phpMyAdmin 的說明文件。

2013年8月20日 星期二

製作 Debian 的 USB 開機碟

之前製作 Debian 的 USB 開機光碟要用 syslinux 之類的方式,之前爬過一些文,總覺得步驟挺繁瑣的。這幾天爬到 "製作 Debian Linux USB 開機安裝磁碟" 這篇文章,然後又翻閱了 Debian 的文件後,在 "使用混合 CD 或 DVD 映像制作 U 盘" 這節裡發現原來製作 USB 開機光碟變得很簡單。

首先,確定 USB 碟的裝置 /dev/sdX,然後下載 Debian 的 ISO 檔 (debian-7.1.0-amd64-netinst.iso),然後執行以下指令即可:

$ sudo cp debian-7.1.0-amd64-netinst.iso /dev/sdX
$ sudo sync

接著,就可以用這個 USB 碟開機,並安裝 Debian。

2013年8月19日 星期一

設定 Linux Mint 15 的 Auto login (自動登入)

一般而言,我並不喜歡使用 auto login (自動登入),因為這麼一來就可能存在一些風險。不過,既然我將 Linux Mint 15 安裝在 VMware Player 的虛擬機裡,那麼使用 auto login 有時反而方便許多。設定 Linux Mint 15 使用 auto login 有兩個方法,如下。

在安裝 Linux Mint 指定 auto login

在 安裝 Linux Mint 時需要建立一個使用者帳號,此時安裝程式的選項裡,有一個「login automatically」的選項,若勾選起來該帳號將自動登入。

在安裝完成後再指定 auto login

稍早提到,我並不喜歡使用 auto login,也因此在安裝 Linux Mint 時,通常我不會勾選「login automatically」的選項。但,若安裝妥 Linux Mint 後,我才想要啟用 auto login 呢?

此時,有兩處需要設定。首先是將系統設定裡,找到「User Accounts」這項,然後在即將使用自動登入的帳號的「Automatic Login」改成 ON。

接著,需要修改「Login Window」這項,在 Security 裡,將「Enable Automatic Login」勾選起來,並選擇即將使用自動登入的帳號,這樣就設定完成了。

2013年7月18日 星期四

第八屆全球城市小姐「網路最佳人氣王票選活動」拉票

朋友彤彤 (林俞彤) 參加了今年的「第八屆全球城市小姐」台灣區選拔大賽,然後這比賽弄了個「網路最佳人氣王票選活動」。

目前 2013 第八屆全球城市小姐網路最佳人氣王票選活動已經開始了,一日每個人次可以投六票,請大家努力投給 10 號的 林俞彤 (參選人第一組),感謝!

票選活動網頁: http://220.128.139.243/MGCP/index.jsp

俞彤的個人短片: http://youtu.be/G_vQB0byNOE

俞彤的粉絲頁: https://www.facebook.com/TungTung.natsuki