July, 2009


9
Jul 09

用 tsocks 和 proxychains 使 Linux 下所有软件能够翻墙

情况
由于最近在中国某个地方爆发了 riot, 所以境内很多网站又是无法访问 (twitter.com、facebook.com 等),让我们这些网民很无奈。

使用 SSH 翻墙
我曾经介绍过如何使用 SSH 来建立一个 SOCKS 代理服务器,让你能够在 Firefox 里正常访问以上所提起的网址。然而不是所有 Linux 软件都能支持代理服务器。如果你最热爱的 Linux 工具需要访问”被封”的网站,又没有嵌入的代理支持,该怎么办呢?
遇到这种情况当然不要放弃该软件… 毕竟我们用的系统是 Linux 而不是以前让我们咳声叹气,丧失信心的 Windows,总有一个方法去解决问题。

举个例子吧
我不久前发现了 Twitter 这个网站。我一开始不经常用,也搞不明白别人为什么对这个 web 2.0 服务都着了迷。后来我在推特上跟的人越来越多,跟着我的人亦是日益增多,不知不觉我也迷上了该网站,天天都会上。凡是经常用推特的人一般都会用一个推特的客户端,这才能跟得上朋友们的状态更新和最火热的网络新闻。本人作为 Ubuntu 的用户,我自然就选了 Gwibber 这个基于 GNOME 的客户端来访问我的推特。这个软件功能很丰富,用起来得心应手,不过总有一个问题让我有点遗憾,就是 Gwibber 还不听从 GNOME 的代理设置。平时这也不是一个很大的问题,但是每遇中国网络封锁较严重时,都会让我暂时无法使用该软件。

解决方案… Tsocks
经过几个 Google 搜索,我最终很高兴地发现 Linux 有一个能够强迫任何软件通过 SOCKS 代理上网的工具,其名就是 tsocks。Tsocks 是一个透明 SOCKS 代理软件,只要你电脑有一个连接到国外服务器的 SSH 隧道,你就能让任何软件翻墙。

安装并配置 Tsocks
以下说明都是为了那些使用 Ubuntu 的 Linux 用户,不过在别的 Linux 发行版下,安装的过程应该与此差不多。

在终端中:

sudo apt-get install tsocks

修改配置文件:

sudo nano /etc/tsocks.conf

将其内容改成以下几行并保存退出:

local = 192.168.1.0/255.255.255.0 #local表示本地的网络,也就是不使用socks代理的网络
server = 127.0.0.1 # SOCKS 服务器的 IP
server_type = 5 # SOCKS 服务版本
server_port = 9999 #SOCKS 服务使用的端口

你可能需要修改一下以上内容,用你自己的 SSH 隧道设置。

运行软件
用 tsocks 运行你的软件很简单,在终端中:

tsocks 你的软件 &

我现在运行 Gwibber 都是这样运行的:

tsocks gwibber &

祝你们翻墙愉快!

EDIT—————–>

我今天还发现了另外一个工具,其功能似乎比 tsocks 要更丰富,配置起来更简单,而且不会那么容易出错。这个工具就是 proxychains。以下有配置方法:

sudo apt-get install proxychains

修改配置文件 (/etc/proxychains.conf),应该如下:

# proxychains.conf  VER 2.0
#
#        HTTP, SOCKS4, SOCKS5 tunneling proxifier.
#

# The option below identifies how the ProxyList is treated.
# only one option should be uncommented at time,
# otherwise the last appearing option will be accepted
#
# Dynamic - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# at least one proxy must be online to play in chain
# (dead proxies are skipped)
# otherwise EINTR is returned to the app
#
# Strict - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# all proxies must be online to play in chain
# otherwise EINTR is returned to the app
#
# Random - Each connection will be done via random proxy
# (or proxy chain, see  chain_len) from the list
# this option is good for scans

dynamic_chain
#strict_chain
#random_chain

# Make sense only if random_chain
chain_len = 2

# Quiet mode (no output)
#quiet_mode

# Write stats about good proxies to proxychains.stats
#write_stats

#Some timeouts in milliseconds
#
tcp_read_time_out 15000
tcp_connect_time_out 10000

[ProxyList]
# ProxyList format
#       type  host  port [user pass]
#       (values separated by 'tab' or 'blank')
#
#
#        Examples:
#
#            	socks5	192.168.67.78	1080	lamer  secret
#		http	192.168.89.3	8080	justu	hidden
#	 	socks4	192.168.1.49	1080
#	        http	192.168.39.93	8080
#
#
#       proxy types: http, socks4, socks5
#        ( auth types supported: "basic"-http  "user/pass"-socks )
#
#http 	10.0.0.5 3128
socks5 127.0.0.1 9999
socks4 127.0.0.1 9050

注意事项:

  1. 要选 dynamic_chain 而不是 random_chain
  2. 可以列举几个代理服务器,proxychains 会按顺序用,代理无法访问即自动选用下一个
  3. 代理服务器要根据自己电脑的情况自行调整

运行 proxychains
运行 proxychains 跟运行 tsocks 完全一样。在终端中:

proxychains 你的软件 &

比如说:

proxychains chromium-browser &

我还是推荐你使用 proxychains!


9
Jul 09

Install latest VLC 1.0 in Ubuntu using the Launchpad Repository

As some of you may have heard by now, VLC reached its version 1.0 milestone yesterday and is already available for download for use on your OS of preference bringing you plenty of new features.

New Features

  • Free, Open Source and cross-platform
  • Independant of systems codecs to support most video types
  • Live recording
  • Instant pausing and Frame-by-Frame support
  • Finer speed controls
  • New HD codecs (AES3, Dolby Digital Plus, TrueHD, Blu-Ray Linear PCM, Real Video 3.0 and 4.0, …)
  • New formats (Raw Dirac, M2TS, …) and major improvements in many formats…
  • New Dirac encoder and MP3 fixed-point encoder
  • Video scaling in fullscreen
  • RTSP Trickplay support
  • Zipped file playback
  • Customizable toolbars
  • Easier encoding GUI in Qt interface
  • Better integration in Gtk environments
  • MTP devices on linux
  • AirTunes streaming
  • New skin for the skins2 interface

Whilst it may take a while before packages start hitting the repositories for your favourite linux distributions, for those of you who are in a hurry to try out the latest version and happen to be running on Ubuntu, here is a quick method to download and install the latest version.

Launchpad Repository
Whilst older versions of VLC are already available in the repositories provided by Ubuntu, the newest version has not yet been rolled out. Don’t despair however… Videolan provide an alternative PPA repository hosted on Launchpad which has the latest edition of your favourite media player.

Installing VLC 1.0
To install VLC 1.0, fire up a terminal and follow the instructions below:

Add the repository:

sudo nano /etc/apt/sources.list.d/vlc.list

For Jaunty, paste in the lines below, save and exit:

deb http://ppa.launchpad.net/c-korn/vlc/ubuntu jaunty main
deb-src http://ppa.launchpad.net/c-korn/vlc/ubuntu jaunty main

Add the key for the Launchpad PPA:

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 7613768D

Update your repositories:

sudo apt-get update

Install:

sudo apt-get install vlc vlc-plugin-esd mozilla-plugin-vlc

That should prompt apt to look for the latest version in the repositories and to download and install it for you. Next time you fire up VLC you should now see that the version number is 1.0!

vlc_1.png

Source: Install VLC on Ubuntu


5
Jul 09

在 Linux 下使用你的网站主机作为加密代理服务器

曾经介绍过如何使用 Amazon EC2 建立自己的代理服务器来“翻墙“。用这个方法翻墙虽然网速很快,但还是有些缺点。Amazon EC2 是收费的,而且按小时算,所以不能随时都开着我的代理服务器。另外,每次想用代理的时候还得先等一两分钟,让服务器启动。

然而我今天看到了这个贴子,这才发现还可以使用一个普通的网站主机作为我的代理服务器。与 Amazon EC2 不同,普通的网站主机是 24/7 运行的,而且你本来就要用它做你的网站,不用额外花钱。以上帖子是专门写给使用 Dreamhost 的 Windows 用户。不过,凡是有支持 SSH 服务网站主机的 Linux 用户也可以享受翻墙的自由感。我为 Linux 用户编了一个小的 BASH 脚本,其主要功能为:

  • 与网站主机创建一个 SSH 隧道连接
  • SSH 隧道用完之后,安全地关闭 SSH 隧道连接

用这个脚本,我试了一下上平时被 GFW 封杀的 youtube.com… 结果 Firefox 差点让我晕倒了! 用这个代理,网速快极了… 感觉好像我还在英国上网似的 (那边一般都用 8M 以上的宽带) – 你可以看一下视频:

介绍一下脚本的内容

export SSH_HOST=admin@yoursite.com # username@host

这个需要你自己改一下… 就是你的 webhost 给你的 SSH 用户名和主机地址。 格式为 用户名@地址 (凡是用过 SSH 的人都应该知道写什么)

if [ ! -f /tmp/.tunnel ]

看看是否已经有 SSH 隧道开着。有的话就将其关闭。没有就创建新的 SSH 隧道。

ssh -f -D 9999 $SSH_HOST "if [ -f ~/.tunnel ]; then rm ~/.tunnel; fi; while [ ! -f ~/.tunnel ]; do echo > /dev/null; done" &

创建新的 SSH 隧道,设定本地 SOCKS 端口为 9999。隧道将会开着直到远程目录 “~/” 里有人创建 .tunnel 此文件为止。

touch /tmp/.tunnel

在你的电脑上创建 .tunnel 这个文件。这样脚本就知道正开着一个 SSH 隧道。

ssh $SSH_HOST "touch ~/.tunnel"

在远程目录 “~/” 里创建 .tunnel 此文件,这将会断开你电脑与代理服务器的连接

rm /tmp/.tunnel

删除 .tunnel 这个文件。这样脚本就知道 SSH 隧道已关闭。

下载并执行脚本
可以在此下载脚本

下载后放在你的首目录,比如在 ~/bin/。用一个文字编辑器修改脚本里的 ssh 变量并用 chmod 改一下文件权限

chmod u+x tunnel.sh

创建连接
在终端中执行脚本,执行后可以关闭终端。

open_tunnel.png

关闭连接
再次在终端中执行脚本并关闭 Firefox (如果 Firefox 还在用隧道的话,连接暂时无法关闭)

close_tunnel.png

用 SSH 密钥进行授权
你或许注意到了… 以上脚本里没有任何地方可以写下你的 SSH 密码。这就是因为我在用 SSH 密钥来进行电脑与服务器的授权工作,这样更自动化而且比将密码直接写入文本的文件里要安全多了。先打开一个终端,根据一下步骤进行密钥配置:

[jonolumb@jonoxps .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jonolumb/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jonolumb/.ssh/id_rsa
Your public key has been saved in /home/jonolumb/.ssh/id_rsa.pub
The key fingerprint is:
h7:10:49:46:ab:2t:3b:a3:36:2z:15:56:d4:f2:b7:3d jonolumb@jonoxps

请注意,配置时密码要留为空白。

将生成的 /home/jonolumb/.ssh/id_rsa.pub 的内容复制到远程服务器目录下,具体位置是:
~/.ssh/authorized_keys
要保证远程的 authorized_keys 和 本地的 id_rsa 文件的权限均为 700。
这样就可以自动登录到远程服务器了。

配置 Firefox 使用代理
创建了 SSH 隧道之后,就进入 Firefox 并打开:

首选项 --> 高级 --> 连接设置

选择“手动配置代理”并将其设定为:
HTTP 代理: localhost 端口: 9999

firefox_proxy.png

如果你用这个脚本遇到什么问题,请跟我取得联系。我很想听你们的意见。谢谢!


4
Jul 09

Gnome-Colors: Elegant, consistent and colourful GNOME desktop themes

Problem
I have never been a big fan of the default Brown/Orange GNOME themes that ship as standard with each new Ubuntu distribution. Although they are fully functional, they seem quite dull and uninspiring and certainly don’t have any ‘Wow’ factor. Definitely not a way to win over windows/mac users to use Linux.

brown.png

For a while then, I have been trying out various different GNOME themes from Gnome-Look on my computer with varying degrees of success. There are indeed a good number of attractive themes available for download – but the biggest problem I have encountered is that of consistency. Whilst the theme itself may be attractive, it is often hard to find a good icon set which doesn’t clash completely with it. Likewise, the theme is installed, chances are you will feel obliged to go searching around for some matching wallpaper – and the perfectionists among you will also insist on finding a colour coordinated GDM theme to finish off the job. All in all, what should be a quick, simple desktop personalisation task can take quite a few hours – and you won’t necessarily be 100% happy with the result either.

A solution is at hand
The truth is, getting a nice colourful desktop theme with matching wallpaper, icons and GDM doesn’t have to be this complicated. It turns out that there is a brilliant project called Gnome-Colours that has set itself the task of dealing with this problem.

gnomecolorsg.png

From what I have seen from just a couple of days use, I believe that it has the potential to completely revolutionise your GNOME Desktop and make Linux a much more attractive and user friendly Operating System.

The Gnome-Colors is a project that aims to make the GNOME desktop as elegant, consistent and colorful as possible.

The current goal is to allow full color customization of themes, icons, GDM logins and splash screens. There are already six full color-schemes available; Brave (Blue), Human (Orange), Wine (Red), Noble (Purple), Wise (Green) and Dust (Chocolate).

Themes, Icons, GDM and Wallpaper
Gnome-Colors currently provides matching themes, icons, GDM login window and desktop wallpaper in 6 different colours. These are all inter-compatible and are designed to blend together nicely giving your desktop a seamless and consistent feel – a bit like using a Mac! Furthermore, thanks to the power of GNOME, you can mix and match between different colour schemes – so you could have a green theme with blue icons, a purple login window and an orange desktop wallpaper and it would still look pretty damn good!

What it looks like
Enough talking, lets have a look at what this setup actually looks like. In the examples below I am using the Brave (blue) theme on Ubuntu 9.04 – but as mentioned above, there are a total of 6 colour schemes to choose from.

Arc-Colors -GDM login window complete with user list and picture
login_1.png

Arc-Colors – GDM login window with standard text input
login_2.png

Shiki-Colors – Six different colourful GNOME themes
themes.png

Shiki-Colors – An example of what Shiki-Colors looks like running on Ubuntu (the dock at the bottom is GNOME Do)
shiki_colors.png

Arc-Colors – A selection of colourful GDM themes to choose from
gdm.png

Gnome-Colors – Six different icon sets to choose from
icons.png

Getting it up and running on your system
Of course, you’re now probably wondering how you can get such a lush GNOME theme up and running on your own desktop. There are in fact two ways of going about this.

1. Download and install manually from Gnome-Look
The gnome-colors themes, icons, GDM window and wallpapers are all available separately on Gnome-Look for download and installation and can then be configured as mentioned below.

Official Gnome-Colors Repository
Of course, the above method is a tedious and long winded approach to installation – and your themes and icons won’t be updated automatically when changes are made upstream. By far the best way of installing Gnome-Colors is to use their official PPA repository.

Add the Repository:
To do so, open up a terminal and paste the following:

sudo echo "deb http://ppa.launchpad.net/gnome-colors-packagers/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/gnome-colors-packagers/ppa/ubuntu jaunty main" > /etc/apt/sources.list.d/gnome-colors.list

Make sure you change the “jaunty” in the above to your current ubuntu version (hardy, intrepid etc) if you are not running Jaunty 9.04.

Add the key for the repository:

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 2d79f61be8d31a30

Update Repositories:

sudo apt-get update

Install packages:

sudo apt-get install gnome-colors shiki-colors arc-colors

Configure your GNOME Desktop to use Gnome-Colors
In the Ubuntu menu, open:

System --> Preferences --> Appearance

You can select the Gnome-Colors wallpaper of your preference in the “Background” tab and you can choose one of the newly installed Shiki-Colors themes in the “Theme” tab. The Gnome-Colors icons will be selected automatically depending on the colour of the theme.

Now open:

System --> Preferences --> Login Window

You can select an Arc-Colors GDM theme in the “Local” tab.

Summary
Gnome-Colors is looking like a very promising theme pack for GNOME and one of only a few that provide a PPA repository for regular updates. Whilst it may not be for everyone, I would certainly recommend that popular distributions such as Ubuntu and Fedora seriously consider including it as an option in their official releases as it really does enhance the Linux user experience and brings along a lot of eye candy to an operating system that has for quite some time fallen behind in the aesthetics department. I have to say a big thank you to the developers – and I look forward to seeing what else there is to come!