2011年10月31日星期一

LP Solver

http://lpsolve.sourceforge.net/5.5/

http://web.mit.edu/lpsolve_v5520/doc/lp-format.htm

2011年10月27日星期四

Setup the SSH server to use keys for authentication ZZ

http://www.g-loaded.eu/2005/11/10/ssh-with-keys/

https://help.ubuntu.com/community/SSH/OpenSSH/Keys


"Secure Shell or SSH is both a computer program and an associated network protocol designed for logging into and executing commands on a networked computer." -WikiPedia-
An SSH server can be set up in various ways, but in this document I’ll describe how it can be configured to:
  • only support connections through the 2nd version of the SSH protocol (SSH-2)
  • use DSA keys for user authentication, without permitting authentication with passwords
  • allow only a specific group of users to connect

The SSH-2 protocol, apart from many other useful features, provides stronger security than SSH-1. It’s a bit more cpu hungry than the latter, but this should not be a problem. Using the above configuration, someone must be extremely lucky to manage to break into our system.
But, let me say a few words about how the authentication is done. The user creates a keypair, which consists of a private key, that can be protected with a passphrase, and a public key. The public key is transfered to the server and the private key is kept in our workstation. We assume that the user has accounts in both the server machine and his workstation. Everytime he tries to connect to the server, the keys are validated and the user is granted access.

Prerequisites

user account in the SSH server machine.
You need to install the following packages to the SSH server machine:
  • openssh
  • openssh-server
The client machines should have the following:
  • openssh
  • openssh-clients

First things first…

I assume that our server machine (server.example.com) is a headless one and that the SSH server is up and running with the default configuration. This permits users, including root, to login with their username/password combination. I also assume that we have already set up a user account on the server with the username "leopard". From a client machine (pc1.example.com) we connect like this:
# ssh leopard@server.example.com
Keypair generation
The default key directory is "~/.ssh". Create this directory in both the user leopard’s home on the server and in your current home directory on the client machine and chmod it so that only the users have access to it.
# mkdir ~/.ssh
# chmod 0700 ~/.ssh
Now, we will create our keypair on our client machine. The following command creates a standard 1024-bit DSA keypair:
# ssh-keygen -t dsa -f ~/.ssh/id_dsa
You will be asked for a passphrase for the private key. You can type any phrase here or leave it blank. Keep in mind that if you do not set a passphrase for you private key and someone else gets access to it, then it will take him only a few seconds to connect to your user account on the server. Anyway, this is up to you. After the key generation is finished, the files id_dsa(private key) and id_dsa.pub (public key) are created in the ~/.ssh/ directory.
Now, we will copy the public key to the /home/leopard/.ssh/ directory on the server saving it with the name authorized_keys and delete id_dsa.pub from our client machine, just because it’s not needed to be there.
# scp ~/.ssh/id_dsa.pub leopard@server.example.com:~/.ssh/authorized_keys
# rm -f ~/.ssh/id_dsa.pub
Make sure that you chmod both keys so that only the respective users have access to them. Issue the following command on both the server and the client machine:
# chmod 0600 ~/.ssh/*
A limited group of SSH users
As an extra security measure, we will create a new group on the server machine and configure the SSH server to only allow this group’s members to authenticate. So, we create a group named "sshusers" and add user "leopard" to it. This has to be done as root:
# groupadd sshusers
# usermod -a -G sshusers leopard

The SSH Server configuration

The SSH server’s configuration file is /etc/ssh/sshd_config. Most of the default options do not need to be modified. What we’ll do is to set it up so that only the members of the "sshusers" group can authenticate using keys instead of passwords. So, as root, fire up your favourite text editor and edit the server configuration file.
NOTE: It’s a good habit to create backups before editing system files.
The options that need to be modified are shown below:
Port 22
Protocol 2
AddressFamily inet
ListenAddress 192.168.0.1
With these we configure the server to listen on port 22, accept connections only over the SSH-2 protocol, use the IPv4 address family and bind on the 192.168.0.1 IP address. Only the "protocol" option is really critical. You can set the others as you like or leave the defaults.
HostKey /etc/ssh/ssh_host_dsa_key
Uncomment or add this line. This is exactly the same as the default option, but needs to be uncommented in the server configuration file, so that the server shows its DSA key’s fingerprint when the client tries to authenticate the server during the connection process. If this is not set, then the server shows its RSA key’s fingerprint (the reason is unknown to me).
LoginGraceTime 2m
PermitRootLogin no
MaxAuthTries 1
The LoginGraceTime option sets a time limit for the user authentication process. If this time passes and the user has not yet authenticated succesfully, then the server closes the connection. Leave this value to the default "2m" until everything is set up properly, so that you have enough time to read any server messages. After that, you can lower it to a reasonable value. I have set it to "20s".
Setting the "PermitRootLogin" option to "no" the server does not allow root to login directly. You can still use "su" after you have succesfully logged in as a normal user.
The "MaxAuthTries" option sets the maximum login attempts per connection. Since we use keys and key validation never fails, we set it to "1".
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
These are the default options. I just add them here so that you make sure they are set up properly in your config.
RSAAuthentication no
PasswordAuthentication no
UsePAM no
KerberosAuthentication no
GSSAPIAuthentication no
We do not want the server to let users authenticate using passwords or use SSH-1 based authentication methods. You should comment out any Kerberos or GSSAPI options too.
AllowGroups sshusers
Only users that belong to the "sshusers" group can authenticate. Any other user will be rejected without even being given the oportunity to authenticate.
MaxStartups 2
This option specifies the maximum number of concurrent unauthenticated connections to the SSH Server. It has nothing to do with the number of authenticated connections. The default value is "10". We lower this value in order to limit the connections from third parties which do not have an account on our server machine.
Banner /etc/ssh/banner
Finaly, you can set a text file that will be displayed as a banner when someone connects to the server. Just remember that it is displayed before the authentication takes place, so do not be very descriptive. The banner is not really needed.
This is all we have to do. The rest of the configuration options should be left to their default values, unless you need something different. This is up to you.
Restarting the server
Now, that we have finished editing the config file, we need to restart the server, so that our changes take effect. Before that, I would recommend deleting any existing server keys. Don’t worry, they will be recreated as soon as the service is restarted. A quick way to delete all the keys is to:
# rm -f ssh_host*key*
Then restart the server:
# service sshd restart
Note that the key creation time may vary from machine to machine, so it may take a few minutes if the CPU is slow.
The server logging is done through syslog and authentication information is sent to/var/log/secure. This file should not be world-readable.
A last thing is to take a note of the server’s DSA public key fingerprint, so that we can compare it with the fingerprint the server sends to our client when we connect. This is important for connections to the server from locations other than our LAN in order to be sure that we actually connect to our server. On the server console type:
# ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
Take a note of the fingerprint.

Connect to the server

To connect to our SSH server from our client machine (pc1.example.com), we type:
# ssh leopard@server.example.com
I suggest that the first time you connect you should add the -v option to the above command for verbose output.
Before the user authentication takes place, the ssh client will try to authenticate the SSH server. Since, there is no stored information about your server it will present you the server’s public DSA key fingerprint so you can compare it with the fingerprint you had previously taken a note of during the server configuration. If the fingerprints are identical, you can answer positively to the question. At this time the file ~/.ssh/known_hosts is created on your client machine and it contains the trusted SSH server’s information. You will never be asked again if you trust this server. If the fingerprint comparison took you longer than the server’sLoginGraceTime, the user authentication does not take place. Just try to reconnect. This time you will eventually log in succesfully using key authentication.
Hashing the known_hosts file
Because the servers’ hostnames and addresses are stored in plain text in the known_hosts file, hashing it is a good habit. This can be done using the ssh-keygen utility. Type:
# ssh-keygen -H -f ~/.ssh/known_hosts
This process makes it unreadable, but the ssh programs can still read the contents. Make sure you permanently delete the known_hosts.old backup file.
Change your private key’s passphrase
If you ever need to change the private key’s passphrase you can use ssh-keygen:
# ssh-keygen -p -f ~/.ssh/id_dsa

The ssh-agent

Although key authentication has many advantages over the authentication with passwords, it has one significant drawback: we have to type the passphrase every time we make a connection to the SSH server. One solution would be not to use a passphrase for our private key. But, this is unacceptable. If someone else gets access to our key and finds out to which servers we connect, things get really bad. A second solution is to use the ssh-agent (part of the openssh package) which caches our passphrase in the memory and then it’s automatically used when we make the connection to the SSH server. This way, we only need to type the passphrase once. This is by far more secure than not using a passphrase.
The ssh-agent is a small daemon that runs in the background. When it is run, it exports some environment variables (SSH_AUTH_SOCK, SSH_AGENT_PID) which can be used by programs likessh-add in order to manage the agent’s cached info or by other programs like the ssh client in order to use this cached info for user authentication. These environment variables must be available to these programs, so the ssh-agent needs to be started in our login shell. There are many different ways to start the agent. Here I’ll describe a rather simple, but very efficient one.
The ssh-agent’s configuration
What we need is to start the agent when we login to our client machine’s shell and stop it when we log out. So, we add the following line to ~/.bash_profile:
eval `ssh-agent`
Why do we use eval? When the ssh-agent is started, it just prints some commands to the stdout. These commands set and export the environment variables we talked about earlier. We use eval, so that these commands are actually executed, or better, evaluated by the shell, so the environment variables are made available to all applications that can use them.
We add the following line to ~/.bash_logout
eval `ssh-agent -k`
This "unsets" the environment variables and kills the agent every time we logout.
Management of cached passphrases
A small utility called ssh-add is used to manage the cached passphrases.
To add a key to the ssh-agent’s cache, we issue the command:
# ssh-add ~/.ssh/id_dsa
We are prompted for the passphrase. After typing it succesfully, it gets cached. From now on, the cached passphrase will be automatically used for every connection we make to the SSH server. Convenient!
If we store our key to the standard location ~/.ssh/ and name it with the standard filenameid_dsa, then ssh-add can be run without arguments. Our key will be used.
To list the cached keys we type:
# ssh-add -l
To remove a cached key:
# ssh-add -d ~/.ssh/id_dsa
To empty the ssh-agent’s cache:
# ssh-add -D

Further Reading

There are numerous articles around the web about SSH. Just use google. Keep in mind though that all the necessary info is in the man pages. You should not just read them, but rather study them:
  1. The official openssh manuals
  2. The openssh FAQ
-------------------------------------------------------------


Troubleshooting


Encrypted Home Directory


If you have an encrypted home directory, SSH cannot access your authorized_keys file because it is inside your encrypted home directory and won't be available until after you are authenticated. Therefore, SSH will default to password authentication.
To solve this, create a folder outside your home named /etc/ssh/ (replace "" with your actual username). This directory should have 755 permissions and be owned by the user. Move the authorized_keys file into it. Theauthorized_keys file should have 644 premissions and be owned by the user.
Then edit your /etc/ssh/sshd_config and add:
AuthorizedKeysFile    /etc/ssh/%u/authorized_keys

Finally, restart ssh with:
sudo service ssh restart

The next time you connect with SSH you should not have to enter your password.

username@host's password:


If you are not prompted for the passphrase, and instead get just the
username@host's password:

prompt as usual with password logins, then read on. There are a few things which could prevent this from working as easily as demonstrated above. On default Ubuntu installs however, the above examples should work. If not, then check the following condition, as it is the most frequent cause:
On the host computer, ensure that the /etc/ssh/sshd_config contains the following lines, and that they are uncommented;
PubkeyAuthentication yes
RSAAuthentication yes

If not, add them, or uncomment them, restart OpenSSH, and try logging in again. If you get the passphrase prompt now, then congratulations, you're logging in with a key!

Permission denied (publickey)


If you're sure you've correctly configured sshd_config, copied your ID, and have your private key in the .ssh directory, and still getting this error:
Permission denied (publickey).

Chances are, your /home/ or ~/.ssh/authorized_keys permissions are too open by OpenSSH standards. You can get rid of this problem by issuing the following commands:
chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Debugging and sorting out further problems


The permissions of files and folders is crucial to this working. You can get debugging information from both the client and server.
if you think you have set it up correctly , yet still get asked for the password, try starting the server with debugging output to the terminal.
sudo /usr/sbin/sshd -d

To connect and send information to the client terminal
ssh -v ( or -vv) username@host's

Where to From Here?


No matter how your public key was generated, you can add it to your Ubuntu system by opening the file .ssh/authorized_keys in your favourite text editor and adding the key to the bottom of the file. You can also limit the SSH features that the key can use, such as disallowing port-forwarding or only allowing a specific command to be run. This is done by adding "options" before the SSH key, on the same line in the authorized_keys file. For example, if you maintain a CVS repository, you could add a line like this:
command="/usr/bin/cvs server",no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc ssh-dss ...

When the user with the specified key logged in, the server would automatically run /usr/bin/cvs server, ignoring any requests from the client to run another command such as a shell. For more information, see the sshd man page/755
SSH/OpenSSH/Keys (last edited 2011-03-20 15:06:19 by dpm)
This article appeared in the digg.com homepage on November 16th, 2005. I thank all “diggers” by heart.

ssh_exchange_identification: Connection closed by remote host (ZZ)


DATE: TUE MAY 12 00:00:00 -0400 2009

0
Note: Use this only as your last resort, and only if you also have a firewall protecting your server, this is dangerous to apply, and if you do, try to go back to the previous (default) configuration as soon as possible.
When trying to connect via ssh to a server, I got this answer from the server.
ssh_exchange_identification: Connection closed by remote host
If this happens to you too, first start looking if you are using this format to log in the server
ssh -l [existing-server-user ] [ip-of-the-server]
or
ssh [existing-server-user]@[ip-of-the-server]
Then, and here it was my problem, be sure you have correctly set your
/etc/hosts.allow and /etc/hosts.deny
mine was
hosts.allow
#
# /etc/hosts.allow
#

# End of file
which was O.K.
hosts.deny
#
# /etc/hosts.deny
#

ALL: ALL: DENY

# End of file
So it was denying me the access to any port of the server, as soon as I comment the ALL: ALL: DENY line it start working, keep in mind that any change to these files can compromise your server's security, so be careful.

--------------------------------------------

Check files in /var/lib/denyhosts/ as your IP is stored there too. For the future, add your IP to/etc/hosts.allow:
ALL: xx.xx.xx.xx

2011年10月22日星期六

[zz]从零开始傻瓜翻墙攻略:Chrome+SSH

from: http://blog.renren.com/GetEntry.do?id=486627822&owner=249428072

我同学推荐给我一个网址,http://nobodycanstop.us/,进入后在对话框中输入你想要翻墙看的网站,然后点击”GO”。TMD,看YOUTUBE视频速度像飞一样,一个网址等于让下面所有教程作废,操作超级简单,强烈推荐所有浏览到此日志的同学先试用这个网址。向李纪开同学表示感谢~这个翻墙方式全当在上述网站不稳定时留做备用。

零开始傻瓜翻墙攻略:Chrome+SSH

GFW BLOG 作者:GFW BLOG 功夫网

不差钱的,可以直接上taobao购买VPN,包年大概不到一百元,省却很多不必要的麻烦。

喜欢DIY或狂差钱的,往下看。从零开始,为了迅速,请按步骤来;本人刚刚走通(windows 7环境下,XP类似),只要严格按照步骤走,相信马上就能看到曙光。

转载请注明出处:http://idoit41.spaces.live.com

step 1. 申请免费的SSH

<自己已有国外的ftp的话,此步骤可跳过,不过要得到ftp服务器的地址、登录名、密码,及SFTP(即ssh)的端口。>

新申请自己的ssh,推荐两个免费的国外网站,如下:A)的申请过程快捷,如果只需要ssh代理,推荐使用这个;B)功能较强大,提供ftp建站等功能,但是创建账户需要等数个小时。

A) CJB.net

到cjb.net注册申请shell Account,猛击这里:http://www.cjb.net/cgi-bin/shell.cgi?action=signup

select a shell处,选择“bash”即可。

收到注册确认信后,点击里面的链接,激活。

按step 4填入MyEnTunnel,SSH端口号为22或443。

B) atbhost.net

http://www.atbhost.net注册,选择“Free Hosting”这个package下单,选择域名,比如:ilikeit.abthost.us,然后Next,选择:“I am a new customer”,填写注册信息(假定用户名为killwall),email要填正确,用于验证。

片刻之后,会收到验证信,点击里面的链接,激活帐号。这个时候其实帐户还未创建好,需等待不超过12小时(我是5个小时后收到,等待期间可进行后面的步骤),会再收到另一封通知信,告知你Hosting Account已经建立好,含帐户基本信息和Control Panel(即CPanel)的地址(形如: http://ilikeit.atbhost.us:2082),这样你就可以登录并管理自己的帐户了。

登录后,可以使用向导,先把语言设为“中文”,可以一路Next学习一下。回到“HOME”页,点击下面的“FTP帐户”,在“账户管理”里,找到主帐户killwall,点击最后面的“配置FTP客户端”,会看到FTP账户信息,其中SFTP服务器端口即为ssh端口(如2022),记下来,以备后用。

至此,SSH帐户已搞定,后面验证可用性。

C)可参见附录一:免费SSH帐号整理——启光博客

step 2. 安装chrome

猛击下载:Chrome

step 3. 安装chrome扩展Switchy!

在Chrome浏览器中猛击下载: Switchy!

如果上面的地址访问不了,请至这个地址下载和安装:http://www.uushare.com/user/mengzehe/file/2794594 ,将下载文件直接拖入chrome浏览器即可安装。

安装好请关闭。

step 4. 安装MyEnTunnel

猛击下载:MyEnTunnel 3.5.2

解压后,运行:myentunnel.exe

如下图进行配置,注意本地端口的设置,为了不与系统当前设置冲突,建议自行设定一个,如2012,然后点击“连接”,观察“状态”标签页,会有“链接成功”的log出现,表示成功。

step 5. 安装Privoxy

猛击下载: Privoxy 3.0.16

安装之后运行,选择菜单:Options-> Edit Main Configuration,将会用记事本打开,在最后重新起一行加入:forward-socks5 / 127.0.0.1:2012 . // 注意最后有个”.”。

此处的2012需与step 4.MyEnTunnel中的本地端口保持一致。保存,关闭记事本。

关闭Privoxy(在任务栏上的privoxy图标上点右键,选“退出”),然后重新打开Privoxy。

step 6. 配置Switchy!

点击Chrome地址栏右边的地球图标,选择“Options”,打开Switchy!配置页面:

在Proxy Profiles标签页:

1)Profile Name: Free SSH (自己随便起一个)
2)选择Manual Configuration
3)HTTP Proxy:127.0.0.1, Port: 8118(即Privoxy的端口)
4)勾选:“Use the same proxy server for all protocols”

点击“Save”按钮保存。如下图所示。

切换到Switch Rules标签页:

1)勾选: Enable Switch Rules
2)勾选: Online Rule List
Rule List URL填入:http://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt (被墙列表)
Reload Every选择:15 Minutes (*后面还会改动一次)
Proxy Profile选择: Free SSH(与上面的Profile Name保持一致)
3)勾选:AutoProxy Compatible List

点击“Save”按钮保存。如下图所示。

step 7. 测试

关闭Chrome,重新打开。

点击“地球”图标,选择“Auto Switch Mode”,即根据RuleList(即上面的gfwlist)来智能分辨是否采用代理的方式进行访问。

然后在地址栏输入“twitter.com”,感受自由的气息吧。

成功后,可以上面的Reload Every由15Minutes改为3 Hours。

<最后提醒一下:电脑重启后,想继续使用chrome自由翻墙,需要保持MyEnTunnel和Privoxy是正常运行状态。>

#end

翻墙利器”赛风”(Psiphon)代理新网址:http://wrcaonima.info/。被墙网站收集:http://delicious.com/GFWbookmark,请使用GFWlist为标签,帮助我们收集被墙网站的信息。敬请订阅GFW Blog:http://feeds2.feedburner.com/chinagfwblog,邮件订阅:https://groups.google.com/group/gfw-blog。更多翻墙工具介绍和下载: 推客浏览器(http://twitbrowser.net/blog/,墙内镜像:http://tm005.nl.am/),Sesawe(http://www.sesawwe.net/)。翻墙互助小组邮件列表: http://groups.google.com/group/bypassgfw。

附录1 免费SSH账号整理– 启光博客

从 GFW BLOG 作者:GFW BLOG 功夫网

来源:http://www.iewb.net/index.php/qg/1492.html

(1)国内代理网站分享的免费SSH账号两枚

ssh服务器1地址: ssh1.dailiav.com

用户名字:dailiav

密码:321311233

端口:22

ssh服务器2地址: ssh2.dailiav.com

用户名字:dailiavcom

密码:797897533

端口:22

经启光博客2010-06-27测试 可用,速度不错,不过不可以看Youtube视频,可以浏览Twitter等网站,感谢dailiavcom提供!

(2)美国freessh.us免费SSH账号

网站:www.freessh.us

在你打开网站后可以看到两枚SSH账号和密码,为了防止滥用,密码五分钟更换一次,已连接 用户不受影响。

(3)SiteFrost.com提供美国免费空间和免费SSH帐号

申请免费空间,自带的免费SSH账号可以使用,比较稳定,不过空间要人工审核,以后要每月去论坛发贴才可继续使用,虽然麻烦些,但也防止了滥用,而且速度真的不错。

(4)cjb.net专来免费SSH账号

cjb.net这个启光博客推荐过,在Firefox+SSH与Chrome+SSH中都是用的这个网站做演示,速度一般,不过申请特别简单。注册网址:http://www.cjb.net/cgi-bin /shell.cgi?action=signup

(5)一个提供免费SSH账号整理的网站

http://shells.red-pill.eu/

这上面提供很多可以免费申请SSH账号的网站, 第一页提供的那些网站都不错,虽然都是英文站,但对于一个想翻墙的网友来说应该不算什么。