ssh tips & tricks

Download SSH Tips & Tricks

Post on 24-May-2015

7.497 views

Category:

Technology

2 download

Embed Size (px)

DESCRIPTION

第二回ターミナル勉強会 SSH Tips & Tricks

TRANSCRIPT

  • 1. SSH tips & tricks 2012/03/26 GREE Inc. Nobutoshi Ogata

2. Oracle Oracle10cm Oracle 3. 4. 5. 6. zsh 7. screen, tmux, zsh 8. () http://twitter.com/nobu666 http://www.facebook.com/nobutoshi.ogata GREE Inc. 9. SSH 10. *_history 11. *_history 12. 13. SSH better telnet 14. SSH 15. Linux OpenSSH SSH2 sshdtcp/22LISTEN 16. ssh -i USER -l ~/.ssh/id_rsa REMOTE 1-2 17. .ssh/congHost hoge HostName hoge.example.com IdentityFile ~/.ssh/id_rsa.hoge User hoge_userHost moge HostName moge.example.jp IdennityFile ~/.ssh/id_rsa.moge User moge_userHost * ForwardAgent yes ServerAliveInterval 200 ForwardX11 no 18. Remotesedgrep $ ssh host `cmd.txt` 19. ssh-agentssh-add keychain$ eval `ssh-agent`$ ssh-add ssh-agentssh-add keychain 20. ssh-agent (1) eval `ssh-agent` ssh-agent logout kill 21. ssh-agent (2)ssh-reagent () {for agent in /tmp/ssh-*/agent.*; doexport SSH_AUTH_SOCK=$agentif ssh-add -l 2>&1 > /dev/null; thenecho Found working SSH Agent:ssh-add -lreturndoneecho Cannot nd ssh agent - maybe you shouldreconnect and forward it?} 22. SSH (1) 23. SSH (2)$ ssh -o ProxyCommand sshUSER@GATEWAY -W %h:%pUSER@INNER_HOSTHost *-proxy User user ProxyCommand ssh gateway -W %h:%P sshOpenSSH5.4 24. SSH (3)Host host3 ProxyCommand ssh host2 -W %h:%PHost host2 ProxyCommand ssh host1 -W %h:%PHost host1 User ore ssh host3 host1host2host3 25. SSH (4)$ ssh -t GATEWAY ssh REMOTE .ssh/cong -t GATEWAYssh sudo -u USER ssh REMOTE 26. Port Forwarding (1) localhostportRemoteport Remoteportlocalhostport LAN ssh 27. Port Forwarding (2) Weblocal$ sudo ssh -Nf -L80:HOST:80 GATEWAY gatewayhost:80127.0.0.1:80 name base virtual host /etc/hosts 28. Port Forwarding (3) mysqllocal$ ssh -Nf -L13306:HOST:3306 GATEWAY$ mysql -uroot -p -P13306 -h127.0.0.1 POP3 29. Port Forwarding (4) GATEWAYhost host$ ssh -fCN -L 10022:TARGET:22 USER@GATEWAY$ rsync --bwlimit=25600 --progress -az -e ssh -p10022 /path/to/large/le localhost:~/ 30. Resume$ rsync --partial --progress --rsh=sshSOURCE_FILE USER@HOST:DEST_FILE$ rsync --partial --progress --rsh=sshUSER@HOST:SOURCE_FILE DEST_FILE Resume --bwlimit 31. from=!foo.example.com,*.example.com, no-pty, command=ls ssh-rsaAAAAB3NzaC1yc2EAAAADAQ....... .ssh/authorized_keys 192.168.0.?192.168.0.*192.168.0.0/24 foo*.example.com ls 32. Remote Diff$ ssh USER@HOST cat /path/to/remotele | diff /path/to/localle -Remote Disk Mount$ sshfs USER@HOST:/path/to/folder /path/to/mount/point 33. Remote Command with screen$ ssh HOST screen -d -m /heavy/command Login with screen$ ssh -t HOST [ $STY ] || screen -rx ||screen -D -RR 34. $ ssh-copy-id ssh$ pssh -h hostlist.txt -i grep -ri err /var/log http://freecode.com/projects/pssh 35. zsh+tmuxssh # ~/.zshrcif [ $TERM = screen ]; thenfunction ssh_tmux() {eval server=${$#}tmux new-window -n $@ "exec ssh $@"}alias ssh=ssh_tmux 36. ssh# ~/.ssh/congControlMaster autoControlPath ~/.ssh/connections/%r@%h:%p sshd 1sshdssh 37. $ sudo (brew|port) install cocot$ cocot -t UTF-8 -p EUC-JP ssh HOST cygwin -t -p https://github.com/vmi/cocot 38. PROXY ! stoneOUTER$ sudo stone localhost:22 443INNER$ stone proxy.example.com:8080/http10022 CONNECT OUTER:443 HTTP/1.0OUTER$ ssh -p 10022 localhost http://www.gcd.org/sengoku/stone/Welcome.ja.html 39. ~/ ~/.ssh ~/.ssh/authorized_keys ~/.ssh/id_rsa ssh -vvv sshd -d 40. SSH!! 41. Lets man ssh_cong 42.