convert putty key to openssh key

有的合作方给的是putty生成的私钥,为了方便使用需要 把putty格式的转化成openssh格式的pm@debian:~$ puttygen –helpPuTTYgen unidentified build, Jun 22 2012 15:52:56Usage: puttygen ( keyfile | -t type [ -b bits ] )[ -C comment ] [ -P ] [ -q ][ -o output-keyfile ] [ -O type | -l | -L | -p ]-t specify key type when generating (rsa, dsa, rsa1)-b specify number of bits when generating key-C change or specify key comment-P change key passphrase-q quiet: do not display progress bar-O specify output type:private output PuTTY private key formatprivate-openssh export OpenSSH private keyprivate-sshcom export ssh.com private keypublic standard / ssh.com public keypublic-openssh OpenSSH public keyfingerprint output the key fingerprint-o specify output file-l equivalent to `-O fingerprint’-L equivalent to `-O public-openssh’-p equivalent to `-O public’ 1.如果对方给的ppk是带密码的,可以使用puttygen把秘密去掉puttygen xxx.ppk -P输入原有的密码后,新密码为空就行了。2.把ppk格式的转化成openssh的puttygen xxx.ppk -o xxx.txt -O private-openssh这样就可以把xxx.ppk导出为 openssh 的私钥xxx.txt ...

August 30, 2012 · 1 min · pm

使用dnsmasq解决多套测试环境的host绑定

线上线下的多套环境,线上环境N多个机房,每个机房几百个公网IP,机房建设前期的需要给测试提供host列表。为方便在新机房启用前测试快速切换到不同的环境,就试用了一下dnsmasq,觉得还是不错的。 centos5.8自带的版本比较老,就直接下载的源码包编译了一下,编译后只拷出来了dnsmasq程序本身。新搞了个目录按照下面的格式存放。 bin/dnsmasq dnsmasq.conf dnsmasq.hosts failquery.pl restart.shresolv.conf 主配置文件如下 #dnsmasq.conf user=pmno-hostsaddn-hosts=/home/pm/dnsmasq/dnsmasq.hostsresolv-file=/home/admin/dnsmasq/resolv.confcache-size=1500local-ttl=10max-ttl=10log-queries #!/bin/bashPRE=/home/pm/dnsmasqkillall dnsmasq &>/dev/null $PRE/bin/dnsmasq -x $PRE/dnsmasq.pid -C $PRE/dnsmasq.conf -8 $PRE/dns.log -Dkillall -0 dnsmasq && echo "dnsmasq start ok" || echo "dnsmasq start failed" 每次改了配置直接运行一下restart脚本就行了。 因为开启了日志记录,所以随便写了个perl脚本分析日志,可以查看到测试同学访问时我配置的host文件是不是又漏掉的。 #!/usr/bin/perluse strict; use warnings; my %error; my %lack; my $reg=qr/xxx.com|yyyy.com/; #只分析这两个域的域名my $DNSLOG="/home/pm/dnsmasq/dns.log"; open my $LOG,"<$DNSLOG" or die "open dns log failed!\n"; while (my $line=<$LOG>){if($line=~/NXDOMAIN/){if($line=~/]:\s+\w+\s+([\w\.]+)\s+/){my $do=$1; $error{$do}++ if ( $do=~/$reg/) ; }}if($line=~/forwarded/){if($line=~/]:\s+\w+\s+([\w\.]+)\s+/){my $do=$1; $lack{$do}++ if ($do=~/$reg/); }} } close $LOG; my @t=keys%error;delete @lack{@t}; if( keys%lack >0){print "\e[31mhosts lack some domains:\e[m\n";print "\e[1;33m",join("\n",keys%lack),"\e[m\n**************\n"}if( keys%error >0){print "\e[32msome query domains not exist:\e[m\n";print join("\n",keys%error),"\n**************\n"}

August 25, 2012 · 1 min · pm

linux下多标签的ssh客户端

对于系统管理员来说在windows下使用securecrt和xshell其实还是比较方便的。撇开其他的不说,在linux下使用gnome-terminal的时候如果不用screen得手动开一堆标签,使用screen也有很多限制,比如复制一下的时候按ctrl +a +[去进入copy/paste模式, 按2次enter选择要复制的段,然后再ctrl+a+] 把缓冲区的内容复制出来,其实还是不是太方便的,尤其是有时执行命令的时候屏幕滚动输出的同时想直接复制一下,用鼠标还是比较方便的。今天试用了一下pac和gnome connetion manager,都还是比较好用的。相对来所pac的功能比较多一些,gcm里面不能指定字符集编码是个遗憾,因为线上服务器都是用的GBK的编码。为了达到在xshell下clone session不重复输入密码的效果。需要简单的配置一下ssh,其实就是在.ssh下新建config文件,填入host *ControlMaster autoControlPath ~/.ssh/master-%r@%h:%p 这样我们在gnome-terminal下如果已经ssh登陆了一个机器的时候再新开窗户ssh登陆这个机器时就不用输入密码了。 附上pac和gcm的链接地址:http://kuthulu.com/gcm/?module=downloadhttp://sourceforge.net/projects/pacmanager/

August 14, 2012 · 1 min · pm

使用evolution-mapi接收exchange服务器的邮件

公司的邮件服务器是exchange的,在linux下办公就非常不方便。还好现在evolution的mapi插件可以比较好地连exchange 2007 server。在debian里直接aptitude install evolution-mapi安装好后,在evolution里就可以选择mapi方式了。填上exchange服务器的域名,自己的账户和domainname就行了。由于我的邮箱类型是BU\[email protected]的形式,所以配置的时候就是exchange.xx.comusername: XXXdomainname: BU选上use secure connection就行了。具体的使用可以参考FAQhttp://www.go-evolution.org/MAPI_FAQ @@@@@@@@@@@@@@@@@@@ 现在我在debian下安装了一个virtulbox 跑了个windows 2003,安装了WPS和foxmail,用foxmail收邮件还是很方便的。 配置的时候填好exchange服务器,需要注意使用https代理服务器登录,填好msstd地址(与代理服务器相同),使用NTLM验证,然后还要注意第一次填写的帐号不能是BU\user,而是要写成user@BU的形式

August 13, 2012 · 1 min · pm

openwrt wan 802.1x认证

公司的内部有线网络使用802.1x认证,自己搞了个DB120刷OpenWrt把无线转发给自己用。安装好OpenWrt后 主要是把wpad-mini卸载换成wpad,mini版本的不支持802.1x认证。其实wpad就是wpa_supplicant和hostapd的集合。 #!/bin/ashkillal l wpa_supplicant 2>/dev/nullwpa_supplicant -B -D wired -i eth0 -c /etc/802.1x.confsleep 5udhcpc -i eth0其实最好的是wpa_supplicant不以deamon启动,直接看输出显示认证成功后重新获取IP。 2.lan下dhcp时指定内网的DNS服务器 修改一下/etc/config/dhcp配置文件 在config dhcp lan段添加 list ‘dhcp_option’ ‘6,DNS1,DNS2′ 6的含义是 root@OpenWrt:/etc/config# dnsmasq –help dhcpKnown DHCP options:1 netmask2 time-offset3 router6 dns-server7 log-server9 lpr-server13 boot-file-size15 domain-name16 swap-server17 root-path18 extension-path19 ip-forward-enable20 non-local-source-routing21 policy-filter22 max-datagram-reassembly23 default-ttl26 mtu27 all-subnets-local31 router-discovery32 router-solicitation33 static-route34 trailer-encapsulation35 arp-timeout36 ethernet-encap37 tcp-ttl38 tcp-keepalive40 nis-domain41 nis-server42 ntp-server44 netbios-ns45 netbios-dd46 netbios-nodetype47 netbios-scope48 x-windows-fs49 x-windows-dm60 vendor-class64 nis+-domain65 nis+-server66 tftp-server67 bootfile-name68 mobile-ip-home69 smtp-server70 pop3-server71 nntp-server74 irc-server77 user-class93 client-arch94 client-interface-id97 client-machine-id119 domain-search120 sip-server121 classless-static-route125 vendor-id-encap255 server-ip-address

August 10, 2012 · 1 min · pm

DNS性能测试

bind自带的queryperf可以比较方便的对DNS服务器进行性能测试, queryperf的安装比较简单,直接在bind-9.x.x/contrib/queryperf下./configure && make就可以编译好。 README 里有比较详细的使用说明。在测试前需要准备一个域名列表。比如 xx1.dev.net A xx2.dev.net A xx3.dev.net A ………….. xxn.dev.net A 然后使用queryperf -d dnsfile -s DNS_SERVER就能进行测试了。一般不开log的话QPS可以到10W,截图的是虚拟机上部署的bind,而且开了log。 ==== 测试了一下路由器上ar7240的CPU,dns查询的性能能到接近2K。 Statistics: Parse input file: onceEnded due to: reaching end of file Queries per second: 1894.060723 qps

August 7, 2012 · 1 min · pm

使用perl脚本发送gtalk消息

gtalk是使用xmpp协议的,因此可以很方便地利用现有的库来登陆gtalk发送消息。下面是参考了网上资料写的一个perl版本的 #!/usr/bin/perluse strict; use warnings; use Net::XMPP; use utf8; binmode(STDIN, ‘:encoding(utf8)’); binmode(STDOUT, ‘:encoding(utf8)’); binmode(STDERR, ‘:encoding(utf8)’); my $username = "USERNAME"; #用户名,不带@的my $password = "PASSWORD"; #纯文本密码my $re source = "perl_script"; #authcenticate my @login =$connect->AuthSend(username => $username,password => $password,re source => $re source ); if ( $login[0] ne "ok" ){print "login failed: $login[0] -$login[1]\n"; exit(2);

July 28, 2012 · 1 min · pm

找出IO消耗较高的进程

经常碰见服务器IO比较慢,这个是最不能忍受的,因为基本的命令行操作都会非常慢。网上搜了下,可以按照这个方式直接找出耗IO最高的进程名。 1.先停掉syslog然后打开block dumpservice syslog stop echo 1 > /proc/sys/vm/block_dump2.从dmesg的中找到消耗IO的进程dmesg | grep -E “READ|WRITE|dirtied” | grep -E -o ‘([a-zA-Z]*)’ | sort |uniq -c|sort -k1 -gr 排前的比较占用io。如果只想关系到读或者写的也可以直接只搜READ和WRITE。 3.恢复系统。 ```bash echo 0 > /proc/sys/vm/block_dumpservice syslog start

June 27, 2012 · 1 min · pm

OOM续

最近维护测试服务器越来越多出现OOM。每次都是改改内核参数,貌似有点用处。但是这个治标不治本,源头没有找到。 自己先了解了一下一些基础性的东西。每次OOM后查看messages日志都能看到 Jun 18 17:10:23 free-72-222 kernel: oom-killer: gfp_mask=0xd0Jun 18 17:10:23 free-72-222 kernel: Mem-info:Jun 18 17:10:23 free-72-222 kernel: DMA per-cpu:Jun 18 17:10:23 free-72-222 kernel: cpu 0 hot: low 2, high 6, batch 1Jun 18 17:10:23 free-72-222 kernel: cpu 0 cold: low 0, high 2, batch 1Jun 18 17:10:23 free-72-222 kernel: cpu 1 hot: low 2, high 6, batch 1Jun 18 17:10:23 free-72-222 kernel: cpu 1 cold: low 0, high 2, batch 1Jun 18 17:10:23 free-72-222 kernel: cpu 2 hot: low 2, high 6, batch 1Jun 18 17:10:27 free-72-222 kernel: cpu 2 cold: low 0, high 2, batch 1Jun 18 17:10:27 free-72-222 kernel: cpu 3 hot: low 2, high 6, batch 1Jun 18 17:10:27 free-72-222 kernel: cpu 3 cold: low 0, high 2, batch 1Jun 18 17:10:27 free-72-222 kernel: Normal per-cpu:Jun 18 17:10:27 free-72-222 kernel: cpu 0 hot: low 32, high 96, batch 16Jun 18 17:10:27 free-72-222 kernel: cpu 0 cold: low 0, high 32, batch 16Jun 18 17:10:27 free-72-222 kernel: cpu 1 hot: low 32, high 96, batch 16Jun 18 17:10:27 free-72-222 kernel: cpu 1 cold: low 0, high 32, batch 16Jun 18 17:10:27 free-72-222 kernel: cpu 2 hot: low 32, high 96, batch 16Jun 18 17:10:27 free-72-222 kernel: cpu 2 cold: low 0, high 32, batch 16…Jun 20 14:46:44 free-72-222 kernel: cpu 2 cold: low 0, high 32, batch 16Jun 20 14:46:44 free-72-222 kernel: cpu 1 cold: low 0, high 32, batch 16Jun 20 14:46:44 free-72-222 kernel: cpu 2 hot: low 32, high 96, batch 16Jun 20 14:46:44 free-72-222 kernel: cpu 2 cold: low 0, high 32, batch 16Jun 20 14:46:44 free-72-222 kernel: cpu 3 hot: low 32, high 96, batch 16Jun 20 14:46:44 free-72-222 kernel: cpu 3 cold: low 0, high 32, batch 16Jun 20 14:46:44 free-72-222 kernel:Jun 20 14:46:44 free-72-222 kernel: Free pages: 35748kB (24320kB HighMem)Jun 20 14:46:44 free-72-222 kernel: protections[]: 0 0 0Jun 20 14:46:44 free-72-222 kernel: protections[]: 0 0 0Jun 20 14:46:44 free-72-222 kernel: protections[]: 0 0 0Jun 20 14:46:44 free-72-222 kernel: protections[]: 0 0 0Jun 20 14:46:44 free-72-222 kernel: Normal free:3304kB min:3336kB low:6672kB high:10008kB active:617956kB inactive:0kB present:729088kB pages_scanned:1293 all_unreclaimable? noJun 20 14:46:44 free-72-222 kernel: protections[]: 0 0 0Jun 20 14:46:44 free-72-222 kernel: HighMem free:24320kB min:512kB low:1024kB high:1536kB active:2836904kB inactive:486976kB present:3358720kB pages_scanned:0 all_unreclaimable? noJun 20 14:46:44 free-72-222 kernel: protections[]: 0 0 0Jun 20 14:46:44 free-72-222 kernel: DMA: 34kB 28kB 616kB 432kB 564kB 1128kB 1256kB 2512kB 21024kB 22048kB 04096kB = 8124kBJun 20 14:46:44 free-72-222 kernel: Normal: 04kB 18kB 016kB 132kB 164kB 1128kB 0256kB 0512kB 11024kB 12048kB 04096kB = 3304kBJun 20 14:46:44 free-72-222 kernel: HighMem: 59424kB 58kB 016kB 032kB 064kB 0128kB 0256kB 1512kB 01024kB 02048kB0*4096kB = 24320kBJun 20 14:46:44 free-72-222 kernel: 428935 pagecache pagesJun 20 14:46:44 free-72-222 kernel: Swap cache: add 0, delete 0, find 0/0, race 0+0Jun 20 14:46:44 free-72-222 kernel: 0 bounce buffer pagesJun 20 14:46:44 free-72-222 kernel: Free swap: 0kBJun 20 14:46:44 free-72-222 kernel: 1026048 pages of RAMJun 20 14:46:44 free-72-222 kernel: 839680 pages of HIGHMEMJun 20 14:46:44 free-72-222 kernel: 10594 reserved pagesJun 20 14:46:44 free-72-222 kernel: 413640 pages sharedJun 20 14:46:44 free-72-222 kernel: 0 pages swap cachedJun 20 14:46:44 free-72-222 kernel: Out of Memory: Killed process 19148 (java). 这样的日志,对于里面的 ...

June 20, 2012 · 5 min · pm

3种常用的ssh端口映射

openssh客户端除了可以作为一个ssh登陆客户端外,还能做一些简单的端口映射,非常使用的。常见的用法有三种: -D 参数 -D [bind_address:]port Specifies a local "dynamic" application-level port forwarding. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the secure channel, and the application protocol is then used to determine where to connect to from the remote machine. Currently the SOCKS4 and SOCKS5 protocols are supported, and ssh will act as a SOCKS server. Only root can forward privileged ports. Dynamic port forwardings can also be specified in the configuration file. -D 指定一个本地端口(如果本地有多个IP的话也可以指定监听某一个IP的端口),充当socks代理的作用的。然后每当有一个到这个端口的链接时,这个链接就被转发到通过ssh隧道转发,然后再从远程服务器上去链接目的地址。1-1024的端口只有root能转发。 ...

May 28, 2012 · 3 min · pm