{"id":17458,"date":"2015-05-21T21:00:26","date_gmt":"2015-05-21T12:00:26","guid":{"rendered":"http:\/\/www.sssg.org\/blogs\/hiro345\/?p=17458"},"modified":"2015-06-22T18:51:05","modified_gmt":"2015-06-22T09:51:05","slug":"ssh%e3%81%ab%e3%82%88%e3%82%8b%e3%83%aa%e3%83%90%e3%83%bc%e3%82%b9%e3%83%9d%e3%83%bc%e3%83%88%e3%83%95%e3%82%a9%e3%83%af%e3%83%bc%e3%83%89","status":"publish","type":"post","link":"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/17458.html","title":{"rendered":"SSH\u306b\u3088\u308b\u30ea\u30d0\u30fc\u30b9\u30dd\u30fc\u30c8\u30d5\u30a9\u30ef\u30fc\u30c9"},"content":{"rendered":"<p>SSH\u306b\u3088\u308b\u30ea\u30d0\u30fc\u30b9\u30dd\u30fc\u30c8\u30d5\u30a9\u30ef\u30fc\u30c9\u306b\u3064\u3044\u3066\u6574\u7406\u3057\u3066\u307f\u307e\u3057\u305f\u3002DHCP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u3057\u3066\u8d77\u52d5\u3059\u308b\u30de\u30b7\u30f3\u306fIP\u30a2\u30c9\u30ec\u30b9\u304c\u5909\u52d5\u3059\u308b\u306e\u3067\u3001IP\u30a2\u30c9\u30ec\u30b9\u3092\u78ba\u8a8d\u3057\u3066\u304b\u3089\u3067\u306a\u3044\u3068\u3001SSH\u30ed\u30b0\u30a4\u30f3\u304c\u3067\u304d\u307e\u305b\u3093\u3002IP\u30a2\u30c9\u30ec\u30b9\u3092\u4f7f\u308f\u306a\u304f\u3066\u3082SSH\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u65b9\u6cd5\u306b\u306f\u3044\u304f\u3064\u304b\u3042\u308a\u307e\u3059\u304c\u3001\u5fdc\u7528\u6027\u306e\u9ad8\u3044\u3082\u306e\u306bSSH\u306b\u3088\u308b\u30ea\u30d0\u30fc\u30b9\u30dd\u30fc\u30c8\u30d5\u30a9\u30ef\u30fc\u30c9\u304c\u3042\u308a\u307e\u3059\u3002SSH\u63a5\u7d9a\u7528\u30b2\u30fc\u30c8\u30a6\u30a7\u30a4\u30de\u30b7\u30f3\u3092\u7528\u610f\u3057\u3066\u304a\u3044\u3066\u3001\u305d\u3053\u3078DHCP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u3057\u3066\u8d77\u52d5\u3059\u308b\u30de\u30b7\u30f3\u304b\u3089SSH\u30ea\u30d0\u30fc\u30b9\u30dd\u30fc\u30c8\u30d5\u30a9\u30ef\u30fc\u30c9\u3067\u63a5\u7d9a\u3055\u305b\u308c\u3070\u3044\u3044\u306e\u3067\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u305d\u306e\u5b9f\u73fe\u624b\u9806\u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u8aac\u660e\u3092\u3057\u307e\u3059\u3002<br \/>\n<!--more--><br \/>\nDHCP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u3057\u3066\u8d77\u52d5\u3059\u308b\u30de\u30b7\u30f3host001\u304b\u3089\u3001\u56fa\u5b9aIP 192.168.0.100 \u3092\u6301\u3064\u30de\u30b7\u30f3\u3078\u30ea\u30d0\u30fc\u30b9\u30dd\u30fc\u30c8\u30d5\u30a9\u30ef\u30fc\u30c9\u3092\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002\u3064\u307e\u308a\u3001192.168.0.100\u304cSSH\u63a5\u7d9a\u7528\u30b2\u30fc\u30c8\u30a6\u30a7\u30a4\u30de\u30b7\u30f3\u3060\u3068\u3057\u307e\u3059\u3002\u307e\u305f\u3001192.168.0.100\u306b\u306fSSH\u63a5\u7d9a\u304c\u3067\u304d\u308b\u30e6\u30fc\u30b6user001\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u3066\u3001\u3053\u308c\u3092\u4f7f\u3046\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u6700\u521d\u306b\u3001host001 \u4e0a\u3067\u9375\u306e\u751f\u6210\u3092\u3057\u3001192.168.0.100\u3078\u30b3\u30d4\u30fc<\/p>\n<pre class=\"brush: bash; gutter: true\">\r\n$ ssh-keygen\r\n$ ssh-copy-id user001@192.168.0.100\r\n<\/pre>\n<p>host001 \u4e0a\u3067\u3001$HOME\/.ssh\/config \u3078\u63a5\u7d9a\u7dad\u6301\u306e\u305f\u3081\u306e\u8a2d\u5b9a\u3092\u8ffd\u52a0<\/p>\n<pre class=\"brush: bash; gutter: true\">\r\nHost 192.168.0.100\r\n   ServerAliveInterval 60\r\n   ExitOnForwardFailure yes\r\n   TCPKeepAlive no\r\n<\/pre>\n<p>host001 \u4e0a\u306b reverse_ssh.sh \u306e\u81ea\u52d5\u63a5\u7d9a\u7528\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u7528\u610f\u3002\u6307\u5b9a\u3057\u305f$CMD\u304c\u5b9f\u884c\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; gutter: true\">\r\n#!\/bin\/sh\r\nhost_ip=&quot;192.168.0.100&quot;\r\nport=&quot;10022&quot;\r\nssh_port=&quot;22&quot;\r\nuser=&quot;user001&quot;\r\nCMD=&quot;ssh -l ${user} -N -f -R ${port}:localhost:${ssh_port} ${host_ip}&quot;\r\npgrep -f -x &quot;$CMD&quot; &gt; \/dev\/null 2&gt;&amp;1 || $CMD\r\n<\/pre>\n<p>crontab -e \u3067 reverse_ssh.sh \u30671\u5206\u3054\u3068\u306b\u81ea\u52d5\u8d77\u52d5\u30c1\u30a7\u30c3\u30af<\/p>\n<pre class=\"brush: bash; gutter: true\">\r\n* * * * * \/bin\/sh \/root\/reverse_ssh.sh\r\n<\/pre>\n<p>\u30ea\u30d0\u30fc\u30b9\u30dd\u30fc\u30c8\u30d5\u30a9\u30ef\u30fc\u30c9\u3092\u63a5\u7d9a\u3055\u308c\u305f\u65b9(\u3053\u3053\u3067\u306f192.168.0.100)\u3067\u306f\u3001localhost\u306e10022\u30dd\u30fc\u30c8\u3078SSH\u63a5\u7d9a\u3059\u308b\u3053\u3068\u3067\u3001SSH\u30ea\u30d0\u30fc\u30b9\u30dd\u30fc\u30c8\u63a5\u7d9a\u3092\u3057\u3066\u304d\u3066\u3044\u308b\u30de\u30b7\u30f3\u3078\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001host001\u306b\u306f\u30e6\u30fc\u30b6 vagrant \u3067\u30d1\u30b9\u30ef\u30fc\u30c9\u8a8d\u8a3c\u306eSSH\u30ed\u30b0\u30a4\u30f3\u304c\u3067\u304d\u308b\u3068\u3057\u307e\u3059\u3002host001\u3078\u63a5\u7d9a\u3059\u308b\u305f\u3081\u306blocalhost\u3068\u6307\u5b9a\u3057\u3066\u3044\u308b\u70b9\u306b\u6ce8\u610f\u3092\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"brush: bash; gutter: true\">\r\n$ netstat -a | grep localhost|grep 10022\r\ntcp6       0      0 localhost:10022         [::]:*                  LISTEN     \r\n$ ssh -l vagrant -p 10022 localhost\r\n<\/pre>\n<p>SSH\u30ea\u30d0\u30fc\u30b9\u30dd\u30fc\u30c8\u63a5\u7d9a\u3092\u3057\u3066\u304d\u3066\u3044\u308b\u30de\u30b7\u30f3\u306eIP\u30a2\u30c9\u30ec\u30b9\u3092\u78ba\u8a8d\u3059\u308b\u306b\u306f192.168.0.100\u3067\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002hostname -I\u306e\u30b3\u30de\u30f3\u30c9\u304chost001\u4e0a\u3067\u5b9f\u884c\u3055\u308c\u308b\u306e\u3067IP\u30a2\u30c9\u30ec\u30b9\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; gutter: true\">\r\n$ ssh -l vagrant -p 10022 localhost hostname -I\r\nvagrant@localhost&#039;s password: \r\n192.168.1.123 \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SSH\u306b\u3088\u308b\u30ea\u30d0\u30fc\u30b9\u30dd\u30fc\u30c8\u30d5\u30a9\u30ef\u30fc\u30c9\u306b\u3064\u3044\u3066\u6574\u7406\u3057\u3066\u307f\u307e\u3057\u305f\u3002DHCP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u3057\u3066\u8d77\u52d5\u3059\u308b\u30de\u30b7\u30f3\u306fIP\u30a2\u30c9\u30ec\u30b9\u304c\u5909\u52d5\u3059\u308b\u306e\u3067\u3001IP\u30a2\u30c9\u30ec\u30b9\u3092\u78ba\u8a8d\u3057\u3066\u304b\u3089\u3067\u306a\u3044\u3068\u3001SSH\u30ed\u30b0\u30a4\u30f3\u304c\u3067\u304d\u307e\u305b\u3093\u3002IP\u30a2\u30c9\u30ec\u30b9\u3092\u4f7f\u308f\u306a\u304f\u3066 &hellip; <a href=\"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/17458.html\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[1209,198],"class_list":["post-17458","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux","tag-ssh"],"_links":{"self":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/17458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/comments?post=17458"}],"version-history":[{"count":7,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/17458\/revisions"}],"predecessor-version":[{"id":17552,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/17458\/revisions\/17552"}],"wp:attachment":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/media?parent=17458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/categories?post=17458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/tags?post=17458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}