SSHÊÇÒ»¸ö·Ç³£Î°´óµÄ¹¤¾ß£¬Èç¹ûÄãÒªÔÚ»¥ÁªÍøÉÏÔ¶³ÌÁ¬½Óµ½·þÎñÆ÷£¬ÄÇôSSHÎÞÒÉÊÇ×î¼ÑµÄºòÑ¡¡£ÏÂÃæÊÇͨ¹ýÍøÂçͶƱѡ³öµÄ25¸ö×î¼ÑSSHÃüÁÄã±ØÐëÀμÇÓÚÐÄ¡£
1¡¢¸´ÖÆSSHÃÜÔ¿µ½Ä¿±êÖ÷»ú£¬¿ªÆôÎÞÃÜÂëSSHµÇ¼
ssh-copy-id user@host
Èç¹û»¹Ã»ÓÐÃÜÔ¿£¬ÇëʹÓÃssh-keygenÃüÁîÉú³É¡£
2¡¢´ÓijÖ÷»úµÄ80¶Ë¿Ú¿ªÆôµ½±¾µØÖ÷»ú2001¶Ë¿ÚµÄ ssh ËíµÀ
ssh -N -L2001:localhost:80 somemachine
ÏÖÔÚÄã¿ÉÒÔÖ±½ÓÔÚä¯ÀÀÆ÷ÖÐÊäÈëhttp://localhost:2001·ÃÎÊÕâ¸öÍøÕ¾¡£
3¡¢½«ÄãµÄÂó¿Ë·çÊä³öµ½Ô¶³Ì¼ÆËã»úµÄÑïÉùÆ÷
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
ÕâÑùÀ´×ÔÄãÂó¿Ë·ç¶Ë¿ÚµÄÉùÒô½«ÔÚSSHÄ¿±ê¼ÆËã»úµÄÑïÉùÆ÷¶Ë¿ÚÊä³ö£¬µ«Òź¶µÄÊÇ£¬ÉùÒôÖÊÁ¿ºÜ²î£¬Äã»áÌýµ½ºÜ¶à˻˻Éù¡£
4¡¢±È½ÏÔ¶³ÌºÍ±¾µØÎļþ
ssh user@host cat /path/to/remotefile | diff /path/to/localfile ¨C
ÔڱȽϱ¾µØÎļþºÍÔ¶³ÌÎļþÊÇ·ñÓвîÒìʱÕâ¸öÃüÁîºÜ¹ÜÓá£
5¡¢Í¨¹ýSSH¹ÒÔØĿ¼/Îļþϵͳ
sshfs name@server:/path/to/folder /path/to/mount/point
´Óhttp://fuse.sourceforge.net/sshfs.htmlÏÂÔØsshfs£¬ËüÔÊÐíÄã¿çÍøÂ簲ȫ¹ÒÔØÒ»¸öĿ¼¡£
6¡¢Í¨¹ýÖмäÖ÷»ú½¨Á¢SSHÁ¬½Ó
ssh -t reachable_host ssh unreachable_host
Unreachable_host±íʾ´Ó±¾µØÍøÂçÎÞ·¨Ö±½Ó·ÃÎʵÄÖ÷»ú£¬µ«¿ÉÒÔ´Óreachable_hostËùÔÚÍøÂç·ÃÎÊ£¬Õâ¸öÃüÁîͨ¹ýµ½reachable_hostµÄ¡°Òþ²Ø¡±Á¬½Ó£¬´´½¨Æðµ½unreachable_hostµÄÁ¬½Ó¡£
7¡¢Í¨¹ýÄãµÄµçÄÔ£¬¸´ÖÆÔ¶³Ì host1 Ö÷»úÉϵÄÎļþµ½Ô¶³Ì host2 Ö÷»úÉϵÄÎļþ
ssh root@host1 ¡°cd /somedir/tocopy/ && tar -cf ¨C .¡± | ssh root@host2 ¡°cd /samedir/tocopyto/ && tar -xf -¡±
Èç¹ûÖ»ÓÐÄãÄÜͬʱ·ÃÎÊ host1 ºÍ host 2 £¬µ«ËüÃDz»ÄÜ·ÃÎÊÄãµÄÖ÷»ú£¨Òò´Ë ncat ÊÇÎÞ·¨¹¤×÷µÄ£©£¬¶øÇÒËüÃÇÖ®¼äÒ²ÎÞ·¨Ö±½Ó·ÃÎÊ¡£
8¡¢ÔËÐÐÈκÎÔ¶³ÌÖ÷»úÉ쵀 GUI ³ÌÐò
ssh -fX <user>@<host> <program>
SSH ·þÎñÆ÷¶Ë±ØÐëÒª¾ß±¸ÒÔÏÂÌõ¼þ£º
X11Forwarding yes ££È·±£ X11 ת·¢ÊÇ´ò¿ªµÄ
ͬʱҲ¿ÉÒÔ´ò¿ª
Compression delayed
µ±È»£¬ÄãÒªÄÜ·ÃÎÊÖ÷»úA²ÅÐС£
9¡¢´´½¨µ½Ä¿±êÖ÷»úµÄ³Ö¾Ã»¯Á¬½Ó
ssh -MNf <user>@<host>
ÔÚºǫ́´´½¨µ½Ä¿±êÖ÷»úµÄ³Ö¾Ã»¯Á¬½Ó£¬½«Õâ¸öÃüÁîºÍÄã~/.ssh/configÖеÄÅäÖýáºÏʹÓãº
Host host
ControlPath ~/.ssh/master-%r@%h:%p
ControlMaster no
ËùÓе½Ä¿±êÖ÷»úµÄSSHÁ¬½Ó¶¼½«Ê¹Óó־û¯SSHÌ×½Ó×Ö£¬Èç¹ûÄãʹÓÃSSH¶¨ÆÚͬ²½Îļþ£¨Ê¹ÓÃrsync/sftp/cvs/svn£©£¬Õâ¸öÃüÁ·Ç³£ÓÐÓã¬ÒòΪÿ´Î´ò¿ªÒ»¸öSSHÁ¬½Óʱ²»»á´´½¨ÐµÄÌ×½Ó×Ö¡£
10¡¢Í¨¹ýSSH Ö±½Ó¿ªÆô²¢»¹Ô screen ÃüÁî
ssh -t remote_host screen ¨Cr
Ö±½ÓÁ¬½Óµ½Ô¶³Ì screen »á»°£¨½ÚÊ¡ÁËÎÞÓõĸ¸bash½ø³Ì£©¡£
11¡¢¶Ë¿Ú¼ì²â£¨ÇÃÃÅ£©
knock <host> 3000 4000 5000 && ssh -p <port> user@host && knock <host> 5000 4000 3000
ÔÚÒ»¸ö¶Ë¿ÚÉÏÇÃһϴò¿ªÄ³¸ö·þÎñµÄ¶Ë¿Ú£¨ÈçSSH£©£¬ÔÙÇÃһϹرոö˿ڣ¬ÐèÒªÏÈ°²×°knockd£¬ÏÂÃæÊÇÒ»¸öÅäÖÃÎļþʾÀý¡£
[options]
logfile = /var/log/knockd.log
[openSSH]
sequence = 3000,4000,5000
seq_timeout = 5
command = /sbin/iptables -A INPUT -i eth0 -s %IP% -p tcp ¨Cdport 22 -j ACCEPT
tcpflags = syn
[closeSSH]
sequence = 5000,4000,3000
seq_timeout = 5
command = /sbin/iptables -D INPUT -i eth0 -s %IP% -p tcp ¨Cdport 22 -j ACCEPT
tcpflags = syn
12¡¢É¾³ýÎı¾ÎļþÖеÄÒ»ÐÐÄÚÈÝ£¬ÓÐÓõÄÐÞ¸´
ssh-keygen -R <the_offending_host>
ÔÚÕâÖÖÇé¿öÏ£¬×îºÃʹÓÃרҵµÄ¹¤¾ß¡£
13¡¢Í¨¹ýSSHÔËÐи´ÔÓµÄÔ¶³ÌshellÃüÁî
ssh host -l user $(<cmd.txt)
¸ü¾ßÒÆÖ²ÐԵİ汾£º
ssh host -l user ¡°`cat cmd.txt`¡±
14¡¢Í¨¹ýSSH½«MySQLÊý¾Ý¿â¸´ÖƵ½Ð·þÎñÆ÷
mysqldump ¨Cadd-drop-table ¨Cextended-insert ¨Cforce ¨Clog-error=error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@newhost ¡°mysql -uUSER -pPASS NEW_DB_NAME¡±
ͨ¹ýѹËõµÄSSHËíµÀDumpÒ»¸öMySQLÊý¾Ý¿â£¬½«Æä×÷ΪÊäÈë´«µÝ¸ømysqlÃüÁÎÒÈÏΪÕâÊÇǨÒÆÊý¾Ý¿âµ½Ð·þÎñÆ÷×î¿ì×îºÃµÄ·½·¨¡£
15¡¢É¾³ýÎı¾ÎļþÖеÄÒ»ÐУ¬ÐÞ¸´¡°SSHÖ÷»úÃÜÔ¿¸ü¸Ä¡±µÄ¾¯¸æ
sed -i 8d ~/.ssh/known_hosts
16¡¢´Óһ̨ûÓÐSSH-COPY-IDÃüÁîµÄÖ÷»ú½«ÄãµÄSSH¹«Ô¿¸´ÖƵ½·þÎñÆ÷
cat ~/.ssh/id_rsa.pub | ssh user@machine ¡°mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys¡±
Èç¹ûÄãʹÓÃMac OS X»òÆäËüûÓÐssh-copy-idÃüÁîµÄ*nix±äÖÖ£¬Õâ¸öÃüÁî¿ÉÒÔ½«ÄãµÄ¹«Ô¿¸´ÖƵ½Ô¶³ÌÖ÷»ú£¬Òò´ËÄãÕÕÑù¿ÉÒÔʵÏÖÎÞÃÜÂëSSHµÇ¼¡£
17¡¢ÊµÊ±SSHÍøÂçÍÌÍÂÁ¿²âÊÔ
yes | pv | ssh $host ¡°cat > /dev/null¡±
ͨ¹ýSSHÁ¬½Óµ½Ö÷»ú£¬ÏÔʾʵʱµÄ´«ÊäËٶȣ¬½«ËùÓд«ÊäÊý¾ÝÖ¸Ïò/dev/null£¬ÐèÒªÏÈ°²×°pv¡£
Èç¹ûÊÇDebian£º
apt-get install pv
Èç¹ûÊÇFedora£º
yum install pv
£¨¿ÉÄÜÐèÒªÆôÓöîÍâµÄÈí¼þ²Ö¿â£©¡£
18¡¢Èç¹û½¨Á¢Ò»¸ö¿ÉÒÔÖØÐÂÁ¬½ÓµÄÔ¶³ÌGNU screen
ssh -t user@some.domain.com /usr/bin/screen ¨CxRR
ÈËÃÇ×ÜÊÇϲ»¶ÔÚÒ»¸öÎı¾ÖÕ¶ËÖдò¿ªÐí¶àshell£¬Èç¹û»á»°Í»È»Öжϣ¬»òÄã°´ÏÂÁË¡°Ctrl-a d¡±£¬Ô¶³ÌÖ÷»úÉϵÄshell²»»áÊܵ½Ë¿ºÁÓ°Ï죬Äã¿ÉÒÔÖØÐÂÁ¬½Ó£¬ÆäËüÓÐÓõÄscreenÃüÁîÓС°Ctrl-a c¡±£¨´ò¿ªÐµÄshell£©ºÍ¡°Ctrl-a a¡±£¨ÔÚshellÖ®¼äÀ´»ØÇл»£©£¬Çë·ÃÎÊhttp://aperiodic.net/screen/quick_referenceÔĶÁ¸ü¶à¹ØÓÚ screenÃüÁîµÄ¿ìËٲο¼¡£
19¡¢¼ÌÐøSCP´óÎļþ
rsync ¨Cpartial ¨Cprogress ¨Crsh=ssh $file_source $user@$host:$destination_file
Ëü¿ÉÒÔ»Ö¸´Ê§°ÜµÄrsyncÃüÁµ±Äãͨ¹ýVPN´«Êä´óÎļþ£¬È籸·ÝµÄÊý¾Ý¿âʱÕâ¸öÃüÁî·Ç³£ÓÐÓã¬ÐèÒªÔÚÁ½±ßµÄÖ÷»úÉÏ°²×°rsync¡£
rsync ¨Cpartial ¨Cprogress ¨Crsh=ssh $file_source $user@$host:$destination_file local -> remote
»ò
rsync ¨Cpartial ¨Cprogress ¨Crsh=ssh $user@$host:$remote_file $destination_file remote -> local
20¡¢Í¨¹ýSSH W/ WIRESHARK·ÖÎöÁ÷Á¿
ssh root@server.com ¡®tshark -f ¡°port !22¡å -w -¡¯ | wireshark -k -i ¨C
ʹÓÃtshark²¶×½Ô¶³ÌÖ÷»úÉϵÄÍøÂçͨÐÅ£¬Í¨¹ýSSHÁ¬½Ó·¢ËÍÔʼpcapÊý¾Ý£¬²¢ÔÚwiresharkÖÐÏÔʾ£¬°´ÏÂCtrl+C½«Í£Ö¹²¶×½£¬µ« Ò²»á¹Ø±Õwireshark´°¿Ú£¬¿ÉÒÔ´«µÝÒ»¸ö¡°-c #¡±²ÎÊý¸øtshark£¬ÈÃËüÖ»²¶×½¡°#¡±Ö¸¶¨µÄÊý¾Ý°üÀàÐÍ£¬»òͨ¹ýÃüÃû¹ÜµÀÖض¨ÏòÊý¾Ý£¬¶ø²»ÊÇÖ±½Óͨ¹ýSSH´«Êä¸øwireshark£¬ÎÒ½¨ÒéÄã¹ýÂËÊý ¾Ý°ü£¬ÒÔ½ÚÔ¼´ø¿í£¬tshark¿ÉÒÔʹÓÃtcpdumpÌæ´ú£º
ssh root@example.com tcpdump -w ¨C ¡®port !22¡ä | wireshark -k -i ¨C
21¡¢±£³ÖSSH»á»°ÓÀ¾Ã´ò¿ª
autossh -M50000 -t server.example.com ¡®screen -raAd mysession¡¯
´ò¿ªÒ»¸öSSH»á»°ºó£¬ÈÃÆä±£³ÖÓÀ¾Ã´ò¿ª£¬¶ÔÓÚʹÓñʼDZ¾µçÄÔµÄÓû§£¬Èç¹ûÐèÒªÔÚWi-FiÈȵãÖ®¼äÇл»£¬¿ÉÒÔ±£Ö¤Çл»ºó²»»á¶ªÊ§Á¬½Ó¡£
22¡¢¸üÎȶ¨£¬¸ü¿ì£¬¸üÇ¿µÄSSH¿Í»§¶Ë
ssh -4 -C -c blowfish-cbc
Ç¿ÖÆʹÓÃIPv4£¬Ñ¹ËõÊý¾ÝÁ÷£¬Ê¹ÓÃBlowfish¼ÓÃÜ¡£
23¡¢Ê¹ÓÃcstream¿ØÖÆ´ø¿í
tar -cj /backup | cstream -t 777k | ssh host ¡®tar -xj -C /backup¡¯
ʹÓÃbzipѹËõÎļþ¼Ð£¬È»ºóÒÔ777k bit/sËÙÂÊÏòÔ¶³ÌÖ÷»ú´«Êä¡£Cstream»¹Óиü¶àµÄ¹¦ÄÜ£¬Çë·ÃÎÊhttp://www.cons.org/cracauer/cstream.html#usageÁ˽âÏêÇ飬ÀýÈ磺
echo w00t, i¡¯m 733+ | cstream -b1 -t2
24¡¢Ò»²½½«SSH¹«Ô¿´«Êäµ½Áíһ̨»úÆ÷
ssh-keygen; ssh-copy-id user@host; ssh user@host
Õâ¸öÃüÁî×éºÏÔÊÐíÄãÎÞÃÜÂëSSHµÇ¼£¬×¢Ò⣬Èç¹ûÔÚ±¾µØ»úÆ÷µÄ~/.sshĿ¼ÏÂÒѾÓÐÒ»¸öSSHÃÜÔ¿¶Ô£¬ssh-keygenÃüÁîÉú³ÉµÄÐÂÃÜÔ¿¿É ÄܻḲ¸ÇËüÃÇ£¬ssh-copy-id½«ÃÜÔ¿¸´ÖƵ½Ô¶³ÌÖ÷»ú£¬²¢×·¼Óµ½Ô¶³ÌÕ˺ŵÄ~/.ssh/authorized_keysÎļþÖУ¬Ê¹ÓÃSSHÁ¬½Ó ʱ£¬Èç¹ûÄãûÓÐʹÓÃÃÜÔ¿¿ÚÁµ÷ÓÃssh user@hostºó²»¾Ã¾Í»áÏÔʾԶ³Ìshell¡£
25¡¢½«±ê×¼ÊäÈ루stdin£©¸´ÖƵ½ÄãµÄX11»º³åÇø
ssh user@host cat /path/to/some/file | xclip
ÄãÊÇ·ñʹÓÃscp½«Îļþ¸´ÖƵ½¹¤×÷ÓõçÄÔÉÏ£¬ÒԱ㸴ÖÆÆäÄÚÈݵ½µç×ÓÓʼþÖУ¿xclip¿ÉÒÔ°ïµ½Ä㣬Ëü¿ÉÒÔ½«±ê×¼ÊäÈ븴ÖƵ½X11»º³åÇø£¬ÄãÐèÒª×öµÄ¾ÍÊǵã»÷Êó±êÖмüÕ³Ìù»º³åÇøÖеÄÄÚÈÝ¡£
Èç¹ûÄ㻹ÓÐÆäËüSSHÃüÁî¼¼ÇÉ£¬»¶ÓÔÚ±¾ÎÄÆÀÂÛÖÐÌû³ö¡£ÁíÍ⣬Ïëѧµ½¸ü¶à Shell ÃüÁÇëÏÂÔØ×îÅ£BµÄ Linux Shell ÃüÁîPDF Êֲᡣ
ÍƼöÐÅÏ¢
- linuxÃüÁîѧϰ±Ê¼Ç£¨11£©£ºnlÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨5£©£ºrmÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨4£©£ºmkdirÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨1£©£ºlsÃüÁî
- ½«CentosµÄyumÔ´¸ü»»Îª¹úÄڵİ¢ÀïÔÆÔ´
- ʹÓÃNginxÌí¼Óheader·ÀÖ¹ÍøÒ³±»frame
- linuxϼÓËÙscp´«Êä´óÎļþµÄËÙ¶È
- linuxϵͳÉ϶ÔnginxÈÕÖ¾·Ö¸î´¦Àí
- lnmp/nginxϵͳÕæÕýÓÐЧµÄͼƬ·ÀµÁÁ´ÍêÕûÉèÖÃÏê½â
- Í»ÆÆÊ®Íò²¢·¢µÄNginxµÄÅäÖü°ÓÅ»¯
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- ²éÕÒ²¢É¾³ý.svnĿ¼Îļþ
- redis ÆßÖÖÊý¾ÝÀàÐ͵ÄʹÓó¡¾°
- linux ÏÂÎļþ¸´ÖƵ½windowsÏÂÂÒÂëµÄ½â¾ö°ì·¨
- nginx³öÏÖ502 upstream sent too big he....
- linuxÏÂsudoÅäÖÃÏê½â
- linuxÃüÁîѧϰ±Ê¼Ç£¨15£©£ºtailÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨14£©£ºheadÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨13£©£ºlessÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨12£©£ºmoreÃüÁî
- ¼ÓÃÜËã·¨±È½Ï3DES AES RSA ECC MD5 SHA1µÈ
ÆÀÂÛ