1、使用 ssh 不用输入密码使用 ssh 不用输入密码 - putty 版很多朋友都用是putty在windows上登陆Linux/Unix来管理的. 以前写过一个在Linux上用ssh-keygen生成public/private对来做为认证,而不用输入密码的帖子.好多朋友就想知道怎么让putty也能这样.小弟这几天有空,试了一下.特将步骤写下,仅供参考. 1.生成public/private对. 这个好办,puttygen就行了.出现如图(1)的界面.然后选中下面的SSH2RSA,再点击Generate就会生成如图(2)的界面.这个过程中要不停的动鼠标,因为它好象是用这个做为随机数的种子的.
2、然后点击Saveprivatekey来保存私钥.公钥可以保存,也可以不保存.全部选中如图(2)的蓝色部分.然后ctrl+c保存到剪贴板.登陆到你想要访问的主机上,打开/.ssh/authorized_keys文件,将刚刚保存到剪贴板的东东粘贴过去.保存后就行了. 2.访问. 这个比在Linux上要麻烦一点.因为没有默认的用户名,也没用默认的home.所以,用如下语法来访问. putty-ic:usrbinssh-private.ppk-lwangzw192.168.21.33其中192.168.21.33是主机IP(主机名也可以),-lwangzw是用户名,-ic:usrbinssh-priv
3、ate.ppk是指定用哪个key来认证. 这样就搞定了. 因为那个进入的语法太麻烦,小弟干脆写了一个linux.bat文件,里面就只有那一行.然后把这个文件放在桌面上,鼠标双击就进入Linux了.:em11:em11: putty的说明里还有什么用pagnet来保存key的,我没细看,有兴趣的朋友可以看一下. 1、 保存Session后,可以用puttysessionname直接连接,不用那么复杂的命令行 2、记得chmod700/.ssh&chmod600/.ssh/authorized_keys,要不然酒会出现serverrefuseourkey的错误。2、 弹弓呀,在bat中写成这样就不
4、出现黑框框了呀,用start: startD:puttyputty.exe-iD:puttymykeys126-ssh-private.ppk-lroot192.168.168.126SSH 的一些安全小技巧一,前言 關於ssh的好處,相信不用我多說了吧? 簡而言之,之前的rpccommand與telnet都全可用ssh代替. 比方如下的這些常見功能: -遠端登錄 sshuserremote.machine -遠端執行 sshuserremote.machinecommand. -遠端複制 scpuserremote.machine:/remote/path/local/path scp/lo
5、cal/pathuserremote.machine:/remote/path -Xforward ssh-Xuserremote.machine xcommand. -Tunnel/Portforward ssh-L1234:remote.machine:4321userremote.machine ssh-R1234:local.machine:4321userremote.machine ssh-L1234:other.machine:4321userremote.machine 至於詳細的用法,我這就不說了.請讀者自行研究吧. 我這裡要說的,是針對ssh服務為大家介紹一些安全技巧,希望
6、大家用得更安心些. 二,實作 (實作以RedHat9為範例) 1)禁止root登錄 #vi/etc/ssh/sshd_config PermitRootLoginno 2)廢除密碼登錄,強迫使用RSA驗證(假設ssh帳戶為user1) #vi/etc/ssh/sshd_config RSAAuthenticationyes PubkeyAuthenticationyes AuthorizedKeysFile.ssh/authorized_keys PasswordAuthenticationno #servicesshdrestart #su-user1 $mkdir/.ssh2;/dev/n
7、ull $chmod700/.ssh $touch/.ssh/authorized_keys $chmod644/.ssh/authorized_keys - 轉往client端: $ssh-keygen-trsa (按三下enter完成不需設密碼,除非您會用ssh-agent。) $scp/.ssh/id_rsa.pubuser1server.machine:id_rsa.pub (若是windowsclient,可用puttygen.exe產生publickey, 然後複制到server端後修改之,使其內容成為單一一行.) - 回到server端: $cat/id_rsa.pub;/.ss
8、h/authorized_keys $rm/id_rsa.pub $exit 3)限制su/sudo名單: #vi/etc/pam.d/su authrequired/lib/security/$ISA/pam_wheel.souse_uid #visudo %wheelALL=(ALL)ALL #gpasswd-auser1wheel 4)限制ssh使用者名單 #vi/etc/pam.d/sshd authrequiredpam_listfile.soitem=usersense=allowfile=/etc/ssh_usersonerr=fail #echouser1;/etc/ssh_u
9、sers 5)封鎖ssh連線並改用web控管清單 #iptables-IINPUT-ptcp-dport22-jDROP #mkdir/var/www/html/ssh_open #cat;/var/www/html/ssh_open/.htaccess;/var/www/html/ssh_open/ssh_open.phpEND ? /Setdirpathforiplist $dir_path=.; /Setfilenameforiplist $ip_list=ssh_open.txt; /Getclientip $user_ip=$_SERVERREMOTE_ADDR; /allowspe
10、cifyingipifneeded if($_GETmyip) $user_ip=$_GETmyip; /checkingIPformat if($user_ip=long2ip(ip2long($user_ip) /Putclientiptoafile if(!($file=fopen($dir_path/$ip_list,w+) echoPermissiondenied!; echoPlsCheckyourrightstodir$dir_pathorfile$ip_list; else fputs($file,$user_ip); fclose($file); echoclientip($
11、user_ip)hasputinto$dir_path/$ip_list; else echoInvalidIPformat!;ssh_open.txtwasnotchanged.; ?; END #touch/var/www/html/ssh_open/ssh_open.txt #chmod640/var/www/html/ssh_open/* #chgrpapache/var/www/html/ssh_open/* #chmodg+w/var/www/html/ssh_open/ssh_open.txt #chmodo+t/var/www/html/ssh_open #servicehtt
12、pdrestart #mkdir/etc/iptables #cat;/etc/iptables/sshopen.shEND #!/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin list_dir=/var/www/html/ssh_open list_file=$list_dir/ssh_open.txt chain_name=ssh_rules mail_to=root #clearchainifexits,orcreatechain. iptables-L-n|/bin/grep-qChain$chain_name& iptables-F$chai
13、n_name true | iptables-N$chain_name iptables-IINPUT-ptcp-dport22-j$chain_name #clearchainwhenneeded $1=clear& iptables-F$chain_name exit0 #donothingwhilelistisempty -s$list_file|exit1 #addrule iptables-A$chain_name-ptcp-dport22-s$($list_file)-jACCEPT& echosshopenedto$(;/etc/services #cat;/etc/xinetd
14、.d/sshopen;/etc/cron.d/sshopen;/etc/iptables/sshblock.sh;$PERM_LIST done END #chmod+x/etc/firewall/sshblock.sh #cat;/etc/hosts.allowEND sshd:ALL:spawn(/etc/firewall/sshblock.sh)&:ALLOW END 這樣,那些亂trySSH的家夥,頂多能試5次(LIMIT可調整),然後就給BLOCK掉了. 此外,在PERM_LIST的ip,也可提供給iptables的初始script,來個永久性封閉: foriin$(;/etc/xi
15、netd.d/finger;/etc/hosts.allow;/var/chroot/etc/passwd 5.修改/etc/pam.d/sshd在末尾加上一句 sessionrequiredpam_chroot.so 6.修改/etc/security/chroot.conf 增加一行abc/var/chroot保存后,使用abc通过ssh登录即可sainux 回复于:2005-09-07 12:04:04让你熬到那么晚真是不好意思 今天早上我按照你给的步骤试了,从Windows下的SSH终端登录,输入密码后显示没有/bin/bash文件,cp了个bash文件到/chroot/bin后可以登
16、录了。 但是用SSHfiletransfer输入密码后提示Failedtoopenasecurefiletransfersession.问题应该出在哪里呢?怎么才能让filetransfer可以正常使用呢?compnik 回复于:2005-09-07 13:35:12是要把bash拷过去的,我忘写了,你要chownabc/var/chroot/home/abc的compnik 回复于:2005-09-07 14:19:02mkdir-p/var/chroot/usr/libexec/openssh cp/usr/libexec/openssh/sftp-server/var/chroot/usr/libexec/openssh find/lib/-maxdepth1(-typef-o-typel)-execln/var/chroot/lib; find/usr/lib/-maxdepth1(-typef-o-typel)-execln/var/chroot/lib;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1