{"id":1195,"date":"2019-04-08T11:06:44","date_gmt":"2019-04-08T03:06:44","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=1195"},"modified":"2019-04-08T11:06:44","modified_gmt":"2019-04-08T03:06:44","slug":"linux%e8%bf%90%e7%bb%b4%e4%ba%ba%e5%91%98%e5%85%b1%e7%94%a8root%e5%b8%90%e6%88%b7%e6%9d%83%e9%99%90%e5%ae%a1%e8%ae%a1","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=1195","title":{"rendered":"Linux\u8fd0\u7ef4\u4eba\u5458\u5171\u7528root\u5e10\u6237\u6743\u9650\u5ba1\u8ba1"},"content":{"rendered":"<div class=\"rich_media_meta_list\"><em id=\"post-date\" class=\"rich_media_meta rich_media_meta_text\">2016-11-02<\/em>\u00a0<a id=\"post-user\" class=\"rich_media_meta rich_media_meta_link rich_media_meta_nickname\"><\/a>\u8fd0\u7ef4\u90e8\u843d<\/div>\n<div id=\"js_content\" class=\"rich_media_content \">\n<div data-md-url=\"https:\/\/mp.weixin.qq.com\/cgi-bin\/appmsg?t=media\/appmsg_edit&amp;action=edit&amp;type=10&amp;appmsgid=504485190&amp;token=1943017853&amp;lang=zh_CN\">\n<h3>\u4e00\u3001\u5e94\u7528\u573a\u666f<\/h3>\n<p>\u5728\u4e2d\u5c0f\u578b\u4f01\u4e1a\uff0c\u516c\u53f8\u4e0d\u540c\u8fd0\u7ef4\u4eba\u5458\u57fa\u672c\u90fd\u662f\u4ee5root \u8d26\u6237\u8fdb\u884c\u670d\u52a1\u5668\u7684\u767b\u9646\u7ba1\u7406\uff0c\u7f3a\u5c11\u4e86\u8d26\u6237\u6743\u9650\u5ba1\u8ba1\u5236\u5ea6\u3002\u4e0d\u51fa\u95ee\u9898\u8fd8\u597d\uff0c\u51fa\u4e86\u95ee\u9898\uff0c\u5c31\u5f88\u96be\u627e\u51fa\u6e90\u5934\u3002<\/p>\n<p>\u8fd9\u91cc\u4ecb\u7ecd\u4e0b\uff0c\u5982\u4f55\u5229\u7528\u7f16\u8bd1bash \u4f7f\u4e0d\u540c\u7684\u5ba2\u6237\u7aef\u5728\u4f7f\u7528root \u767b\u9646\u670d\u52a1\u5668\u4f7f\uff0c\u8bb0\u5f55\u5404\u81ea\u7684\u64cd\u4f5c\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u7ed3\u5408ELK \u65e5\u5fd7\u5206\u6790\u7cfb\u7edf\uff0c\u6765\u6536\u96c6\u767b\u9646\u64cd\u4f5c\u65e5\u5fd7<\/p>\n<h3>\u4e8c\u3001\u73af\u5883<\/h3>\n<p><strong>\u670d\u52a1\u5668\uff1a<\/strong>centos 6.5\u3001Development tools\u3001\u4f7f\u7528\u5bc6\u94a5\u8ba4\u8bc1\uff0cSElinux \u5173\u95ed\u3002<\/p>\n<p><strong>\u5ba2\u6237\u7aef\uff1a<\/strong>\u751f\u6210\u5bc6\u94a5\u5bf9\uff0c\u7528\u4e8e\u767b\u5f55\u670d\u52a1\u5668 \uff082\u53f0\uff09<\/p>\n<h3>\u4e09\u3001\u642d\u5efa\u90e8\u7f72<\/h3>\n<blockquote>\n<h6>\u670d\u52a1\u5668\u64cd\u4f5c : 192.168.30.72<\/h6>\n<\/blockquote>\n<h5>1\u3001\u4e0b\u8f7d\u7f16\u8bd1bash<\/h5>\n<pre><code>[root@open1 ~]# wget http:\/\/ftp.gnu.org\/gnu\/bash\/bash-4.1.tar.gz\n[root@open1 ~]# tar xvf bash-4.1.tar.gz\n[root@open1 ~]# cd bash-4.1<\/code><\/pre>\n<h5>2\u3001 \u5148\u4fee\u6539\u4e0b config-top.c\u6587\u4ef6,\u5927\u698294\u884c\u3001104\u884c\uff0c\u7531\u4e8ec \u8bed\u8a00\u4e2d \u6ce8\u91ca\u662f\/**\/ \uff0c\u6240\u4ee5\u4e0d\u8981\u5220\u9664\u9519\u4e86\u3002\u4fee\u6539\u5982\u4e0b\uff1a<\/h5>\n<pre><code>[root@open1 bash-4.1]# vim config-top.c\n#define SSH_SOURCE_BASHRC\n#define SYSLOG_HISTORY<\/code><\/pre>\n<h5>3 \u4fee\u6539\u4e0bbashhist.c \u6587\u4ef6\uff0c\u8ba9\u7ec8\u7aef\u4e0a\u7684\u547d\u4ee4\u8bb0\u5f55\u5230\u7cfb\u7edfmessages \u4e2d\uff0c\u5e76\u4e14\u4ee5\u6307\u5b9a\u7684\u683c\u5f0f\u3002\u5e76\u4f20\u5165\u83b7\u5f97\u7684\u53d8\u91cf\u3002\u4fee\u6539\u540e\u7684\u5185\u5bb9\u5982\u4e0b\uff1a<\/h5>\n<pre><code>[root@open1 bash-4.1]# vim bashhist.c\n#... \u7701\u7565\u90e8\u5206\u6bb5\u843d\nvoid\nbash_syslog_history (line)\n \u00a0 \u00a0const char *line;\n{\n \u00a0char trunc[SYSLOG_MAXLEN];\n \u00a0 \u00a0const char *p;\n \u00a0 \u00a0p = getenv(\"NAME_OF_KEY\");\n \u00a0if (strlen(line) &lt; SYSLOG_MAXLEN)\n \u00a0 \u00a0syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, \"HISTORY: PID=%d PPID=%d SID=%d \u00a0User=%s USER=%s CMD=%s\", getpid(), getppid(), getsid(getpid()), \u00a0current_user.user_name, p, line);\n \u00a0else\n \u00a0 \u00a0{\n \u00a0 \u00a0 \u00a0strncpy (trunc, line, SYSLOG_MAXLEN);\n \u00a0 \u00a0 \u00a0trunc[SYSLOG_MAXLEN - 1] = ' ';\n \u00a0 \u00a0 \u00a0syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, \"HISTORY (TRUNCATED): PID=%d \u00a0PPID=%d SID=%d User=%s USER=%s CMD=%s\", getpid(), getppid(), getsid(getpid()), current_user.user_name, p, trunc);\n \u00a0 \u00a0}\n}<\/code><\/pre>\n<h5>4 \u914d\u7f6e\u5b89\u88c5\u8def\u5f84\uff0c\u7f16\u8bd1\u5b89\u88c5\uff0c\u7f16\u8bd1\u5230\/usr\/local\/\u76ee\u5f55\u4e0b<\/h5>\n<pre><code>[root@open1 bash-4.1]# .\/configure --prefix=\/usr\/local\/bash_new\n[root@open1 bash-4.1]# make &amp;&amp; make install\n...\nif test \"bash\" = \"gettext-tools\"; then \\\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/bin\/sh \/root\/bash-4.1\/.\/support\/mkinstalldirs \/usr\/local\/bash_new\/share\/gettext\/po; \\\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0for file in Makefile.in.in remove-potcdate.sin quot.sed boldquot.sed en@quot.header en@boldquot.header insert-header.sin Rules-quot \u00a0 Makevars.template; do \\\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/usr\/bin\/install -c -m 644 .\/$file \\\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/usr\/local\/bash_new\/share\/gettext\/po\/$file; \\\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0done; \\\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0for file in Makevars; do \\\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0rm -f \/usr\/local\/bash_new\/share\/gettext\/po\/$file; \\\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0done; \\\n \u00a0 \u00a0 \u00a0 \u00a0else \\\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0: ; \\\n \u00a0 \u00a0 \u00a0 \u00a0fi\nmake[1]: Leaving directory `\/root\/bash-4.1\/po'<\/code><\/pre>\n<h5>5\u3001\u7f16\u8bd1\u5b8c\u6210\u540e\uff0c\u5c06\u65b0\u7684bash \u8ffd\u52a0\u5230 \/etc\/shells \u4e2d\uff0c\u5e76\u4fee\u6539root\u7528\u6237\u7684\u767b\u9646shell \u73af\u5883\u4e3a\u65b0\u7f16\u8bd1\u7684shell<\/h5>\n<pre><code>[root@open1 bash-4.1]# echo \"\/usr\/local\/bash_new\/bin\/bash\" &gt;&gt; \/etc\/shells\n[root@open1 bash-4.1]# cat \/etc\/shells\n\/bin\/sh\n\/bin\/bash\n\/sbin\/nologin\n\/bin\/dash\n\/usr\/local\/bash_new\/bin\/bash<\/code><\/pre>\n<pre><code>[root@open1 bash-4.1]# vim \/etc\/passwd\nroot:x:0:0:root:\/root:\/usr\/local\/bash_new\/bin\/bash<\/code><\/pre>\n<h5>6\u3001\u6ce8\u9500\u5f53\u524droot\u7528\u6237\uff0c\u91cd\u65b0\u767b\u9646\u540e\uff0c\u67e5\u770b\/var\/log\/messages\uff0c\u5982\u4e0b\u5c31\u53ef\u4ee5\u770b\u5230\u8bb0\u5f55\u4e86\u64cd\u4f5c\u547d\u4ee4<\/h5>\n<p><img decoding=\"async\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw\/eHBhY2tldCBiZWdpbj0i77u\/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkJDQzA1MTVGNkE2MjExRTRBRjEzODVCM0Q0NEVFMjFBIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkJDQzA1MTYwNkE2MjExRTRBRjEzODVCM0Q0NEVFMjFBIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QkNDMDUxNUQ2QTYyMTFFNEFGMTM4NUIzRDQ0RUUyMUEiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6QkNDMDUxNUU2QTYyMTFFNEFGMTM4NUIzRDQ0RUUyMUEiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw\/eHBhY2tldCBlbmQ9InIiPz6p+a6fAAAAD0lEQVR42mJ89\/Y1QIABAAWXAsgVS\/hWAAAAAElFTkSuQmCC\" alt=\"\" data-s=\"300,640\" data-type=\"jpeg\" data-src=\"http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/rtibSseGoBicnPSVs26ysb82Q9ZoCvPlf6oRmxrHrQP0a43SbyQwjQdOGUpwXEtiacShBfCO74FFpn7ZDPnpA2vnA\/0?wx_fmt=jpeg\" data-ratio=\"0.0592964824120603\" data-w=\"995\" \/><\/p>\n<h3>\u56db\u3001SSH\u5ba2\u6237\u7aef\u751f\u6210\u5bc6\u94a5\u90e8\u5206<\/h3>\n<h5>1 \u5728client1\u4e0a\uff08192.168.30.99\uff09\u64cd\u4f5c\uff0c\u7528\u6237zhangsan<\/h5>\n<pre><code>[root@rsyslog ~]# ssh-keygen -t rsa -C \"root@zhangsan\"\nGenerating public\/private rsa key pair.\nEnter file in which to save the key (\/root\/.ssh\/id_rsa):\nEnter passphrase (empty for no passphrase):\nEnter same passphrase again:\nYour identification has been saved in \/root\/.ssh\/id_rsa.\nYour public key has been saved in \/root\/.ssh\/id_rsa.pub.\nThe key fingerprint is:\nc8:bd:5d:3b:a5:d9:6d:09:b6:5f:db:55:1d:43:96:3d root@zhangsan\nThe key's randomart image is:\n+--[ RSA 2048]----+\n| \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 oo|\n| \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0oE.|\n| \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 o.|\n| \u00a0 \u00a0 . o \u00a0 \u00a0 \u00a0 \u00a0+|\n| \u00a0 \u00a0 \u00a0o S \u00a0 .o. o|\n| \u00a0 \u00a0 \u00a0 \u00a0 o ..*o.o|\n| \u00a0 \u00a0 \u00a0 \u00a0. . =...=|\n| \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ...=|\n| \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 o.|\n+-----------------+<\/code><\/pre>\n<blockquote>\n<h6>-C \u6ce8\u91ca \uff08\u52a0\u4e0a\u8fd9\u4e2a\u4e5f\u662f\u4e3a\u4e86\u6700\u540e\u8fdb\u884c\u5bf9\u670d\u52a1\u5668\u8bbf\u95ee\u4eba\u5458\u8fdb\u884c\u8fa8\u522b\u7684\u4e00\u4e2a\u5173\u952e\u70b9\uff09<\/h6>\n<\/blockquote>\n<h5>2\u3001\u5c06\u516c\u94a5\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u4e0a\u7684.ssh\/authorized_keys \u6587\u4ef6\u4e2d\u3002ssh-copy-id \u547d\u4ee4\u4f1a\u81ea\u52a8\u5728\u670d\u52a1\u5668\u4e0a\u521b\u5efa.ssh\/authorized_keys\u6587\u4ef6\uff0c\u5373\u4f7f\u8be5\u76ee\u5f55\u4e0d\u5b58\u5728\uff0c\u5e76\u81ea\u52a8\u8d4b\u4e88600\u6743\u9650\u3002<\/h5>\n<pre><code>[root@rsyslog ~]# ssh-copy-id -i \/root\/.ssh\/id_rsa.pub root@192.168.30.72\nroot@192.168.30.72's password:\nNow try logging into the machine, with \"ssh 'root@192.168.30.72'\", and check in:\n\n \u00a0.ssh\/authorized_keys\n\nto make sure we haven't added extra keys that you weren't expecting.<\/code><\/pre>\n<h5>3\u3001client 2\uff08192.168.30.71\uff09 \u4e0a\u540c\u6837\u7684\u64cd\u4f5c\uff0c\u7528\u6237lisi<\/h5>\n<pre><code>[root@swift3 ~]# ssh-keygen -t rsa -C \"root@lisi\"\nGenerating public\/private rsa key pair.\nEnter file in which to save the key (\/root\/.ssh\/id_rsa):\nEnter passphrase (empty for no passphrase):\nEnter same passphrase again:\nYour identification has been saved in \/root\/.ssh\/id_rsa.\nYour public key has been saved in \/root\/.ssh\/id_rsa.pub.\nThe key fingerprint is:\n8f:56:66:91:0c:6e:86:3b:90:19:42:9c:ab:9e:00:f6 root@lisi\nThe key's randomart image is:\n+--[ RSA 2048]----+\n| oo.. \u00a0 . \u00a0 \u00a0 \u00a0 \u00a0|\n| \u00a0o. + o o . \u00a0 \u00a0 |\n| \u00a0 .+ . + + \u00a0 \u00a0 \u00a0|\n|... \u00a0. + \u00a0 . \u00a0 \u00a0 |\n|o.. \u00a0 o S + \u00a0 \u00a0 \u00a0|\n|o \u00a0E \u00a0 . * \u00a0 \u00a0 \u00a0 |\n|o . \u00a0 \u00a0 o . \u00a0 \u00a0 \u00a0|\n| o \u00a0 \u00a0 . \u00a0 \u00a0 \u00a0 \u00a0 |\n| \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 |\n+-----------------+<\/code><\/pre>\n<h5>4\u3001\u4e0a\u4f20\u516c\u94a5\u5230\u670d\u52a1\u5668\u4e0a<\/h5>\n<pre><code>[root@swift3 ~]# ssh-copy-id -i \/root\/.ssh\/id_rsa.pub root@192.168.30.72\nThe authenticity of host '192.168.30.72 (192.168.30.72)' can't be established.\nRSA key fingerprint is 8f:a7:1b:8d:e4:92:ad:ae:ea:1b:fb:67:0b:0b:7c:ac.\nAre you sure you want to continue connecting (yes\/no)? yes\nWarning: Permanently added '192.168.30.72' (RSA) to the list of known hosts.\nroot@192.168.30.72's password:\nNow try logging into the machine, with \"ssh 'root@192.168.30.72'\", and check in:\n\n \u00a0.ssh\/authorized_keys\n\nto make sure we haven't added extra keys that you weren't expecting.<\/code><\/pre>\n<h5>5\u3001\u73b0\u5728\u53bb\u670d\u52a1\u5668\u4e0a\u9a8c\u8bc1\u4e0b\u8be5\u6587\u4ef6<\/h5>\n<pre><code>[root@open1 ~]# cat ~\/.ssh\/authorized_keys\nssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6fM+bpWEP3luauvOjmTB55ugUzVVMesmHCw4RNZ\/C2e+KGXAYuxuAmEBbMcXQQj7OTAqVCQ0PWja58wReyZ7etiUGAtvoSBmSBpTPXteBMl40kDn4GdmXQ9UT\/jnQ9gSZUQYJLMLJGWJks9S4xUI2cZ7oIytclrsUnKuOA1U6+luIJwJu9z7ya5OXh5FmmJQFnYtAEIhrLt4S8Ru5S00c0jiQCRk3RFlHYNc0IR02MXMH7d9bq7l04heAcT\/y1EBS3EwINX8r0y6OridjJPCwxnm1sSfMKvLAbq\/B+ufDjEOp7Y2SatL3qXaiP7NxdnhoJ4+Xar0zCoYi2A9oRGgUQ== root@zhangsan\nssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAupGSgXOWpQfzOVkHXYqN2BjMiAyaFRdKs6Wam3xGpMYRjZbIFX14kNR4CbrQtbUK8YonZPYdXG589blFmqF17sUPCNEqZEjCNer+yzDu+hYg\/jAn4dCVtTBqUtBsTYUHSHIR0srruJ9keHNgU9aDRok8nulMUi\/9Ej0NJZsBQ2npVNCf0YHgAd\/ON5VsBYVLPvAT\/cG3MuCjg5mgtU59qgAHyLKxkfpVc0\/TRZ4eamX\/1V0dsCxx9oYDbpn4YKLBAOaAS4kF6qEdrwRh0ssyWtWOo\/CdyfLXKgwdbPtPfWZ63SM7wY7bAtcdxxu\/QDkYVP+4oDfAtMxXZlY2bT5qMQ== root@lisi<\/code><\/pre>\n<h5>6\u3001\u73b0\u5728\u4e0a\u9762\u4e24\u4e2a\u5ba2\u6237\u7aef\u5df2\u7ecf\u53ef\u4ee5\u514d\u5bc6\u94a5\u767b\u9646\u4e86\uff0c\u73b0\u5728\u53bb\u670d\u52a1\u5668\u4e0a\u914d\u7f6e\uff0c\u5e76\u521b\u5efa\u811a\u672c<\/h5>\n<h3>\u4e94\u3001\u914d\u7f6e\u670d\u52a1\u5668<\/h3>\n<h5>1\u3001\u5728log\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a keys \u6587\u4ef6\uff0c\u7528\u4e8e\u767b\u9646\u65f6\u5b58\u8fdb\u53bb\u516c\u94a5\uff0c\u4e4b\u540e\u5bf9\u5176\u8fdb\u884c\u53d6\u51fa\u5224\u65ad\u7684<\/h5>\n<pre><code>[root@open1 ~]# touch \/var\/log\/keys<\/code><\/pre>\n<h5>2\u3001\u521b\u5efa\u68c0\u6d4b\u811a\u672c\uff0c\u5185\u5bb9\u5982\u4e0b:<\/h5>\n<pre><code>[root@open1 ~]# cat \/etc\/CheckUser.sh\n#!\/bin\/bash\n#conding:utf-8\npid=$PPID\n#\u5728\u81ea\u5df1home\u76ee\u5f55\u5f97\u5230\u6240\u6709\u7684key\uff0c\u5982\u679c\/var\/log\/keys \u6ca1\u6709\u7684\u65f6\u5019\uff0c\u6dfb\u52a0\u8fdb\u53bb\nwhile read line\ndo\ngrep \"$line\" \/var\/log\/keys &gt;\/dev\/null || echo \"$line\" &gt;&gt; \/var\/log\/keys\ndone &lt; $HOME\/.ssh\/authorized_keys\n#\u5f97\u5230\u6bcf\u4e2akey\u7684\u6307\u7eb9\ncat \/var\/log\/keys | while read LINE\ndo\n NAME=$(echo $LINE | awk '{print $3}')\necho $LINE &gt;\/tmp\/keys.log.$pid\n KEY=$(ssh-keygen -l -f \/tmp\/keys.log.$pid | awk '{print $2}')\ngrep \"$KEY $NAME\" \/var\/log\/ssh_key_fing &gt;\/dev\/null || echo \"$KEY $NAME\" &gt;&gt; \/var\/log\/ssh_key_fing\ndone\n#\u5982\u679c\u662froot\u7528\u6237\uff0csecure\u6587\u4ef6\u91cc\u9762\u662f\u901a\u8fc7PPID\u53f7\u9a8c\u8bc1\u6307\u7eb9\nif [ $UID == 0 ]\nthen\nppid=$PPID\nelse\n#\u5982\u679c\u4e0d\u662froot\u7528\u6237\uff0c\u9a8c\u8bc1\u6307\u7eb9\u7684\u662f\u53e6\u5916\u4e00\u4e2a\u8fdb\u7a0b\u53f7\nppid=`\/bin\/ps -ef | grep $PPID |grep 'sshd:' |awk '{print $3}'`\nfi\n#\u5f97\u5230RSA_KEY\u548cNAME_OF_KEY\uff0c\u7528\u6765bash4.1\u5f97\u5230\u5386\u53f2\u8bb0\u5f55\nRSA_KEY=`\/bin\/egrep 'Found matching RSA key' \/var\/log\/secure | \/bin\/egrep \"$ppid\" | \/bin\/awk '{print $NF}' | tail -1`\n if [ -n \"$RSA_KEY\" ];then\nNAME_OF_KEY=`\/bin\/egrep \"$RSA_KEY\" \/var\/log\/ssh_key_fing | \/bin\/awk '{print $NF}'`\nfi\n#\u628aNAME_OF_KEY\u8bbe\u7f6e\u4e3a\u53ea\u8bfb\nreadonly NAME_OF_KEY\nexport NAME_OF_KEY\n\/bin\/rm \/tmp\/keys.log.$pid<\/code><\/pre>\n<h5>3\u3001\u914d\u7f6e profile\uff0c\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4e00\u884c\u5185\u5bb9\uff0c\u5982\u4e0b\uff1a<\/h5>\n<pre><code>[root@open1 ~]# echo \"test -f \/etc\/CheckUser.sh &amp;&amp; . \/etc\/CheckUser.sh\" &gt;&gt; \/etc\/profile<\/code><\/pre>\n<h5>4\u3001\u5728\/etc\/bashrc \u672b\u5c3e\u6dfb\u52a0\u4e0b\u9762\u5185\u5bb9\uff1a<\/h5>\n<pre><code>[root@open1 ~]# tail -1f \/etc\/bashrc\ntest -z \"$BASH_EXECUTION_STRING\" || { test -f \/etc\/CheckUser.sh &amp;&amp; . \/etc\/CheckUser.sh; logger -t -bash -s \"HISTORY $SSH_CLIENT USER=$NAME_OF_KEY CMD=$BASH_EXECUTION_STRING \" &gt;\/dev\/null 2&gt;&amp;1;}<\/code><\/pre>\n<h5>5\u3001\u4fee\u6539sshd \u914d\u7f6e\u6587\u4ef6\uff0c\u5f00\u542fdebug \u6a21\u5f0f\uff0c\u5e76\u91cd\u542fsshd\u670d\u52a1<\/h5>\n<pre><code>[root@open1 ~]# sed -i 's\/#LogLevel INFO\/LogLevel DEBUG\/g' \/etc\/ssh\/sshd_config\n[root@open1 ~]# service sshd restart\nStopping sshd: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ \u00a0OK \u00a0]\nStarting sshd: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ \u00a0OK \u00a0]<\/code><\/pre>\n<h3>\u516d\u3001\u9a8c\u8bc1<\/h3>\n<h5>1\u3001\u5728client1 \u4e0a\u8fdb\u884c\u767b\u9646\uff0c\u5e76\u5220\u9664\u4e2a\u6587\u4ef6\u8bd5\u4e0b\uff08zhangsan\uff09<\/h5>\n<p><img decoding=\"async\" src=\"http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/rtibSseGoBicnPSVs26ysb82Q9ZoCvPlf6ZmyVWvlHHMSDwKyHqwQ1okYicDOs6j6hqRYAu4l1OM8OibBnEvmxvBww\/0?wx_fmt=jpeg\" alt=\"\" data-s=\"300,640\" data-type=\"jpeg\" data-src=\"http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/rtibSseGoBicnPSVs26ysb82Q9ZoCvPlf6ZmyVWvlHHMSDwKyHqwQ1okYicDOs6j6hqRYAu4l1OM8OibBnEvmxvBww\/0?wx_fmt=jpeg\" data-ratio=\"0.15808170515097691\" data-w=\"563\" data-fail=\"0\" \/><\/p>\n<h5>2\u3001\u5728client2 \u4e0a\u8fdb\u884c\u767b\u9646\uff0c\u4e5f\u5220\u9664\u4e2a\u6587\u4ef6\uff0c\u5e76\u6267\u884c\u4e2a\u91cd\u542f\u670d\u52a1\u7684\u547d\u4ee4\uff08lisi\uff09<\/h5>\n<p><img decoding=\"async\" src=\"http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/rtibSseGoBicnPSVs26ysb82Q9ZoCvPlf6vmTveI4s2TlNVYiaCG8bic19sKwgem71FZLlLI3ia4WjyQYsCCicqL64mg\/0?wx_fmt=jpeg\" alt=\"\" data-s=\"300,640\" data-type=\"jpeg\" data-src=\"http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/rtibSseGoBicnPSVs26ysb82Q9ZoCvPlf6vmTveI4s2TlNVYiaCG8bic19sKwgem71FZLlLI3ia4WjyQYsCCicqL64mg\/0?wx_fmt=jpeg\" data-ratio=\"0.17592592592592593\" data-w=\"648\" data-fail=\"0\" \/><\/p>\n<h5>3\u3001\u53bb\u670d\u52a1\u5668\u4e0a\u67e5\u770b\u4e0b messages \u65e5\u5fd7\uff0c\u5185\u5bb9\u5982\u4e0b<\/h5>\n<p><img decoding=\"async\" src=\"http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/rtibSseGoBicnPSVs26ysb82Q9ZoCvPlf63J5vh0zyMkKFXBYfOXk8w9BsynCKIqdYMX5bXTQL3rHicdIeynFRKwQ\/0?wx_fmt=jpeg\" alt=\"\" data-s=\"300,640\" data-type=\"jpeg\" data-src=\"http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/rtibSseGoBicnPSVs26ysb82Q9ZoCvPlf63J5vh0zyMkKFXBYfOXk8w9BsynCKIqdYMX5bXTQL3rHicdIeynFRKwQ\/0?wx_fmt=jpeg\" data-ratio=\"0.16845878136200718\" data-w=\"1116\" data-fail=\"0\" \/><\/p>\n<blockquote>\n<h6>\u901a\u8fc7\u4e0a\u56fe\uff0c\u53ef\u4ee5\u770b\u51fa\uff0c\u4e0d\u901a\u7528\u6237\u7684\u5ba2\u6237\u7aef\u901a\u8fc7\u516c\u94a5\u767b\u9646\u7684\u65b9\u5f0f\uff0c\u5206\u8fa8\u51fa\u4e86\u8c01\u64cd\u4f5c\u4e86\u4ec0\u4e48\uff0c\u4ec0\u4e48\u65f6\u5019\u64cd\u4f5c\u7684<\/h6>\n<\/blockquote>\n<h3>\u4e03\u3001\u7ed3\u675f<\/h3>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6781\u5927\u7684\u89e3\u51b3\u4e86\u591aroot \u7528\u6237\u767b\u9646\u64cd\u4f5c\uff0c\u65e0\u6cd5\u5ba1\u8ba1\u7684\u95ee\u9898\u3002\u5e76\u4e14\u53ef\u4ee5\u7ed3\u5408\u65e5\u5fd7\u8f6c\u53d1\uff0c\u5c06\u7cfb\u7edf\u65e5\u5fd7\u8f6c\u53d1\u5230\u5176\u5b83\u670d\u52a1\u5668\uff0c\u5373\u4f7f\u4e3b\u673a\u88ab\u9ed1\u4e86\uff0c\u4e5f\u80fd\u5177\u4f53\u7684\u5ba1\u67e5\u767b\u9646\u65f6\u95f4\u4ee5\u53ca\u505a\u4e86\u54ea\u4e9b\u64cd\u4f5c\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u539f\u6587\u7ae0\u8f6c\u81ea\uff1ahttps:\/\/mp.weixin.qq.com\/s?__biz=MzIyMDA1MzgyNw==&amp;mid=2651968844&amp;idx=1&amp;sn=bc6cba7f5dcea089f2df4e283d423a76&amp;chksm=8c349d60bb4314765313ebb185236e2da6ea6bcca19de58130a1807e88ec263b1fc09f96abe0&amp;scene=0&amp;pass_ticket=%2Fn3BAiE%2FTvroxeNodAU6Ot0IS1pO1OdPvHoaqHM8e4jR4wKirK6z1q7lMZdD6khH#rd<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>2016-11-02\u00a0\u8fd0\u7ef4\u90e8\u843d \u4e00\u3001\u5e94\u7528\u573a\u666f \u5728\u4e2d\u5c0f\u578b\u4f01\u4e1a\uff0c\u516c\u53f8\u4e0d\u540c\u8fd0\u7ef4\u4eba\u5458\u57fa\u672c\u90fd\u662f\u4ee5root \u8d26\u6237\u8fdb\u884c\u670d\u52a1\u5668\u7684\u767b\u9646\u7ba1\u7406\uff0c\u7f3a\u5c11\u4e86\u8d26\u6237\u6743\u9650\u5ba1\u8ba1\u5236\u5ea6\u3002\u4e0d\u51fa\u95ee\u9898\u8fd8\u597d\uff0c\u51fa\u4e86\u95ee\u9898\uff0c\u5c31\u5f88\u96be\u627e\u51fa\u6e90\u5934\u3002 \u8fd9\u91cc\u4ecb\u7ecd\u4e0b\uff0c\u5982\u4f55\u5229\u7528\u7f16\u8bd1bash \u4f7f\u4e0d\u540c\u7684\u5ba2\u6237\u7aef\u5728\u4f7f\u7528root \u767b\u9646\u670d\u52a1\u5668\u4f7f\uff0c\u8bb0\u5f55\u5404\u81ea\u7684\u64cd\u4f5c\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u7ed3\u5408ELK \u65e5\u5fd7\u5206\u6790\u7cfb\u7edf\uff0c\u6765\u6536\u96c6\u767b\u9646\u64cd\u4f5c\u65e5\u5fd7 \u4e8c\u3001\u73af\u5883 \u670d\u52a1\u5668\uff1acentos 6.5\u3001Development tools\u3001\u4f7f\u7528\u5bc6\u94a5\u8ba4\u8bc1\uff0cSElinux \u5173\u95ed\u3002 \u5ba2\u6237\u7aef\uff1a\u751f\u6210\u5bc6\u94a5\u5bf9\uff0c\u7528\u4e8e\u767b\u5f55\u670d\u52a1\u5668 \uff082\u53f0\uff09 \u4e09\u3001\u642d\u5efa\u90e8\u7f72 \u670d\u52a1\u5668\u64cd\u4f5c : 192.168.30.72 1\u3001\u4e0b\u8f7d\u7f16\u8bd1bash [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1195","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/1195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1195"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/1195\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}