--EOF--
Results tagged “proxy”
--EOF--
--EOF--
--EOF--
SSH
zz From http://zhigang.org/wiki/SSH
目录
通过ssh建立安全隧道(ssh tunnelling,也称端口映射,Port Forwarding)
本地映射(Local Forward)
远程映射(Remote Forward)
公钥认证
配置ssh使用代理服务器,穿越企业防火墙
加快SSH连接速度方法
使用expect实现ssh自动交互
SSH保持连接(KeepAlive)
参考资料
本章记录了自己在使用SSH的过程中遇到的一些问题,及其解决方法。
通过ssh建立安全隧道(ssh tunnelling,也称端口映射,Port Forwarding)
通过ssh的端口映射功能可以方便地存取一下无法直接访问的资源。又分为本地映射(Local Forward)和远程映射(Remote Forward)。
本地映射(Local Forward)
$ ssh -f -g -A -X -N -T -L 1234:remote-host2:5678 user@remote-host或者通过修改ssh的配置文件:
$ cat ~/.ssh/config
Host remote-host
Hostname x.x.x.x (your remote host IP)
LocalForward 1234:remote-host2:5678
User user
$ ssh user@remote-host所有对本地1234端口的访问都通过remote-host被转发到remote-host2的5678端口。有些DMZ中只开放sshd的22端口,通过本地映射,你可以访问远程计算机上的所有服务。
远程映射(Remote Forward)
$ ssh -f -g -A -X -N -T -R 1234:remote-host2:5678 user@remote-host或者通过修改ssh的配置文件:
$ cat ~/.ssh/config
Host remote-host
Hostname x.x.x.x (your remote host IP)
RemoteForward 1234:remote-host2:5678
User user
$ ssh user@remote-host所有对remote-host的1234端口的访问都通过本机被转发到remote-host2的5678端口。通过远程映射,你可以通过家中的机子(有公网IP,可以ssh登录)来访问公司防火墙内部的计算机。
公钥认证
使用公钥认证经常遇到的问题就是一些文件的权限问题。一些问题可以通过查看/var/log/secure来发现。
要配置两台计算机使用公钥认证,可以通过分别在两台机子host1、host2上运行如下脚本:
$ ssh-keygen -t rsa -b 1024 # don't input any password
$ ssh $host1 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ ssh $host2 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys # important!
配置ssh使用代理服务器,穿越企业防火墙
通过 http://zippo.taiyo.co.jp/~gotoh/ssh/connect.html 下载connect.c,编译,拷贝到系统/usr/bin目录:
$ gcc connect.c -o connect
$ sudo cp connect /usr/bin编辑ssh的配置文件~/.ssh/config,增加:
$ cat ~/.ssh/config
Host remote-host
ProxyCommand connect -H your.proxy.com:port %h %p
$ ssh user@remote-host
加快SSH连接速度方法
SSH登录时会进行DNS反查,如果你的DNS Server速度比较慢,会发生等待。知道了原因解决方法就出来了:就是提高域名解析的速度。可以将主机名写到/etc/hosts中来解决。
使用expect实现ssh自动交互
下面是使用expect实现的自动远端命令执行的脚本remote-exec:
# \
exec expect -- "$0" ${1+"$@"}
# remote-exec - execute command on remote host
# Version 0.1
# Zhigang Wang <zhigang.x.wang@oracle.com>
exp_version -exit 5.0
if {$argc!=2} {
send_user "usage: remote-exec command password\n"
send_user "Eg. remote-exec \"ssh user@host ls\\; echo done\" password\n"
send_user "or: remote-exec \"scp /local-file user@host:/remote-file\" password\n"
send_user "or: remote-exec \"scp user@host:/remote-file local-file\" password\n"
send_user "or: remote-exec \"rsync --rsh=ssh /local-file user@host:/remote-file\" password\n"
send_user "Caution: command should be quoted.\n"
exit
}
set cmd [lindex $argv 0]
set password [lindex $argv 1]
eval spawn $cmd
set timeout 120
while {1} {
expect -re "Are you sure you want to continue connecting (yes/no)?" {
# First connect, no public key in ~/.ssh/known_hosts
send "yes\r"
} -re "assword:" {
# Already has public key in ~/.ssh/known_hosts
send "$password\r"
} -re "Permission denied, please try again." {
# Password not correct
exit
} -re "kB/s|MB/s" {
# User equivalence already established, no password is necessary
set timeout -1
} -re "file list ..." {
# rsync started
set timeout -1
} -re "bind: Address already in use" {
# For local or remote port forwarding
set timeout -1
} -re "Is a directory|No such file or directory" {
exit
} -re "Connection refused" {
exit
} timeout {
exit
} eof {
exit
}
}
SSH保持连接(KeepAlive)
可以使用下面的方法:
增加下面的内容到~/.ssh/config或者/etc/ssh/ssh_config:
Host *
ServerAliveInterval 60 # in second执行下面的脚本:
while date; do sleep 10; done当要输入命令时,只需要按下ctrl-c.
参考资料
OpenSSH official site.
OpenSSH Manual Pages.
The Secure Shell(tm) Frequently Asked Questions.
SSH Tunnelling (Port Forwarding).
SSH Port Forwarding.
SSH Proxy Command -- connect.c.
Corkscrew -- tool for tunneling SSH through HTTP proxies.
SSH Host Key Protection.
SSH and ssh-agent.
The Expect Home Page.
Pexpect - a Pure Python Expect-like module.
--EOF--
1.公司只提供23 443 80 端口访问
2.FastDomain主机只提供22端口ssh访问
1.路由器设置端口转发: 443 -> 192.168.1.1:1080
2.路由器运行:ssh -N -g -L 1080:guduo.net:22 xxx@guduo.net
转发所有访问路由器1080端口的请求到guduo.net的22端口
ssh访问路由器1080端口时,实际就是访问guduo.net的22端口,可以看putty访问示例日志:
login as: xxx
xxx@192.168.1.1's password:
Last login: Fri Dec 25 08:07:06 2009 from fast22.fastdomain.com
[xxx@fast22 /home/xxx]
$
3.本地通过plink连接路由器再连接FastDomain建立代理访问:
d:\green_soft\putty\plink.exe -N xxx@路由器WAN -P 443 -pw "xxx_pw" -D 127.0.0.1:1080
如果我在FastDomain购买了Dedicated IP,是否可以通过
ssh -N -g -L 8000:localhost:22 xxx@localhost 来直接开启一个8000端口的ssh服务呢?
路由器上测试:
~ # ssh -N -g -L 1080:192.168.1.1:80 root@192.168.1.1
root@192.168.1.1's password:
将1080也直接指向httpd的80服务~
ssh -N -g -L 1080:guduo.net:22 xxx@guduo.net
所有对本地的1080端口的访问都通过guduo.net被转发到guduo.net的22端口
ssh -N -g -L 1080:guduo.net:22 root@127.0.0.1
所有对本地的1080端口的访问都通过127.0.0.1被转发到guduo.net的22端口
zz From http://zhigang.org/wiki/SSH
本地映射(Local Forward)
$ ssh -f -g -A -X -N -T -L 1234:remote-host2:5678 user@remote-host或者通过修改ssh的配置文件:
$ cat ~/.ssh/config
Host remote-host
Hostname x.x.x.x (your remote host IP)
LocalForward 1234:remote-host2:5678
User user
$ ssh user@remote-host所有对本地1234端口的访问都通过remote-host被转发到remote-host2的5678端口。有些DMZ中只开放sshd的22端口,通过本地映射,你可以访问远程计算机上的所有服务
--EOF--
主机A可以上网,但ICS连接共享被禁用,一般的代理软件也不允许安装,怎么给主机B也提供上网呢?
我使用的办法:
主机A上安装F-SecureSSHServer,开启ssh tunnel功能,安装另外一块网卡,和主机B直连。
主机B上的设置:
使用putty开启ssh连接做socks代理,再使用代理软件来服务,注意需要代理软件支持Remote DNS服务。
若使用全局代理需要注意设置的代理规则:
往127.0.0.1和192.168.0.1的所有连接不使用代理,其它无要求。
使用中发现Proxifier的Portable版本对某些Java可执行程序(如aastocks的MIE)的代理有失效的情况,使用安装版则无此问题。
如果只是希望某些程序上网,则使用SocksCap32更方便。
--EOF--
公司网络限制比较严格,针对很多端口都有限制,比如22这样的端口都限制了,使得没法访问一些ssh的网站。
上有政策,下有对策。为了能够很爽的ssh上BBS灌水看咨询,平时也琢磨着找一些代理软件来使用,前提当然是有合适的socks5代理服务器,而且不能只有一个,至少还得有一个备用哦。
最早也最喜欢且一直在使用的是SocksCap32,绿色,非常简单,稳定,感觉非常好,这就是一直以来使用的经验。最近公司实施了更严格的网络访问策略,才让我觉得SocksCap32的的二个缺点:一是不能针对所有的网络应用程序来进行设置,只能一个一个应用程序添加,这样就有些不方便了,毕竟现在不使用代理的软件是另类了;二是不能开启多个实例,其它软件可以么?呵呵,算了,我就用两个不同的软件来解决吧~
另外一个现在也必须每天上班使用的就是Proxifier了。本来很喜欢ProxyCap,原因还是很简单:配置啥的都很简单,而且感觉和SocksCap32类似,所以开始就准备使用他为所有程序做代理了。可是很大的一个问题就是,他对使用远程DNS支持很不好,或者说我根本不知道如何设置,鄙视我吧,我找到了他的FAQ的说明,也硬是没能设置好,哪位如果设置好了,告诉我吧,我一定用它。
这样我就转投了Proxifier,这个程序看起来笨笨的,但是监控,日志等方面做的非常好,弃用ProxyCap之后我反而更喜欢它了。对它的使用的设置也走过一些弯路,就是实施排除某些应用程序和IP不使用代理的策略时,开始总是设置失败,比较怪异,后来我将程序和IP分开设置后好了。
FreeCap和SocksCap32类似,也得一个一个程序添加,用的很少,有SocksCap32,我就不会用它了。
PermeoSecurity Driver ,据说是Eborder的升级版?它的说明我还看了很久呢~,可恨的是我最后居然没能用上它,设置总是不成功。
最后一个:delegate,我还没使用,今天刚发现的,开源的,有兴趣的可以试试哦:
http://www.delegate.org/delegate/
--EOF--