{"id":116883,"date":"2018-08-27T09:20:10","date_gmt":"2018-08-27T01:20:10","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=116883"},"modified":"2018-08-27T10:37:57","modified_gmt":"2018-08-27T02:37:57","slug":"ssh-no-su","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ssh-no-su.html","title":{"rendered":"\u5982\u4f55ssh\u65e0\u6cd5\u767b\u5f55\u53ef\u4ee5su\u5207\u6362\u7684\u95ee\u9898"},"content":{"rendered":"
\u63a5\u4e1a\u52a1\u4fa7\u540c\u4e8b\u90ae\u4ef6\uff0c\u4e00\u53f0\u73b0\u7f51\u4e3b\u673a\u4f7f\u7528\u6b63\u786e\u7684\u7528\u6237\u540d\u5bc6\u7801\u00a0ssh \u767b\u5f55\u4e0d\u4e0a\uff08\u4e4b\u524d\u6b63\u5e38\uff09\uff0c\u4f7f\u7528\u5176\u4ed6\u7528\u6237 \u201c su - \u8be5\u7528\u6237 \u201d \u8f93\u5165\u5bc6\u7801\u53ef\u4ee5\u6b63\u5e38\u5207\u6362\u8fdb\u53bb\u3002\u800c\u4e14\u4f7f\u7528\u8be5\u7528\u6237\u8fdb\u884c ftp \u767b\u5f55\u4e5f\u6b63\u5e38\u3002<\/p>\n
\u4e3b\u673a\u7cfb\u7edf\uff1aSUSE Linux Enterprise Server 10 (x86_64) sp1 ----\u7cfb\u7edf\u6709\u70b9\u8001\u65e7\u4e86<\/p>\n
\u95ee\u9898\u7528\u6237\uff1aprestat ------\u5176\u4ed6\u7528\u6237\u6b63\u5e38<\/p>\n
\u9996\u5148\u4f7f\u7528prestat \u7528\u6237\u53ca\u5bc6\u7801\u8fdb\u884cssh \u767b\u5f55\u5c1d\u8bd5\uff0c\u53d1\u73b0\u95ee\u9898\u540c\u4e1a\u52a1\u4fa7\u540c\u4e8b\u63cf\u8ff0\u4e00\u81f4\u3002\u6539\u7528root \u76f4\u63a5\u8fdb\u5165\u767b\u5f55\uff0c\u5148\u4f7f\u7528chage\u547d\u4ee4\u67e5\u770b\u7528\u6237\u662f\u5426\u56e0\u5bc6\u7801\u8fc7\u671f\u88ab\u9501\uff08\u8fd9\u6b65\u5b9e\u9645\u4e0a\u53ef\u4ee5\u5ffd\u7565\uff0c\u56e0\u4e3aftp\u767b\u5f55\u53casu\u5207\u6362\u8fc7\u6765\u6b63\u5e38\uff0c\u4e0d\u8fc7\u7a33\u59a5\u8d77\u89c1\uff0c\u8fd8\u662f\u5148\u770b\u4e0b\uff09<\/p>\n
www.361way.com:~ # chage -l prestat\r\nMinimum: 0\r\nMaximum: 99999\r\nWarning: 7\r\nInactive: -1\r\nLast Change: Mar 12, 2015\r\nPassword Expires: Never\r\nPassword Inactive: Never\r\nAccount Expires: Never\r\n<\/pre>\n\u540c\u65f6\u53c8\u7528chage\u547d\u4ee4\u67e5\u770b\u4e86\u4e00\u4e2a\u6b63\u5e38\u7528\u6237\uff0c\u53d1\u73b0\u663e\u793a\u7684\u4e00\u81f4\u3002<\/p>\n
\u6ce8\uff1a\u63a5\u4e0b\u6765\u8fd8\u53ef\u4ee5\u67e5\u770b\u4e0b\/etc\/shadow \u6587\u4ef6\uff0c\u67e5\u770b\u7528\u6237\u662f\u5426\u771f\u6b63\u7684\u88ab\u9501\u5b9a\uff0c\u4e0d\u8fc7\u8fd9\u91cc\u6309\u6392\u969c\u601d\u8def\u5148\u4e0d\u76f4\u5165\u6b63\u9898\u3002\u56e0\u4e3a\u6309\u4e0b\u9762\u7684\u6b65\u9aa4\u53ef\u4ee5\u76f4\u63a5\u5b9a\u4f4d\u6839\u56e0\u3002<\/p>\n
2\u3001message\u65e5\u5fd7\u67e5\u770b<\/strong><\/span><\/div>\n\u4f7f\u7528root\u767b\u5f55\u540e\uff0c\u5207\u6362\u5230\/var\/log\u76ee\u5f55 \uff0c\u5f00\u542f\u4e00\u4e2a\u7ec8\u7aef\u901a\u8fc7tail -f message \u67e5\u770b\u65e5\u5fd7\u53d8\u5316\uff0c\u4f7f\u7528SCRT \u518d\u6b21\u4f7f\u7528prestat \u7528\u6237\u767b\u5f55\uff0c\u67e5\u770b\u767b\u5f55\u65f6\u65e5\u5fd7\u7684\u53d8\u5316\u3002\u901a\u8fc7\u8be5\u65b9\u6cd5\u67e5\u770b\u5230\u4e86\u65e5\u5fd7\u6709\u62a5\u9519\u5982\u4e0b\uff1a<\/p>\n
www.361way.com:\/var\/log # tail -20000 messages |grep deny\r\nApr 9 16:54:37 www.361way.com sshd[11911]: pam_tally(sshd:auth): user prestat (310) tally 39, deny 6\r\nApr 9 17:01:11 www.361way.com sshd[25582]: pam_tally(sshd:auth): user prestat (310) tally 40, deny 6\r\n<\/pre>\n\u4ece\u4e0a\u9762\u53ef\u4ee5\u770b\u5230\uff0c\u7528\u6237\u767b\u5f55\u65f6\u89e6\u53d1\u4e86pam.d\u4e0b\u7684sshd\u767b\u5f55\u8ba4\u8bc1\u76f8\u5173\u6a21\u5757pam_tally \uff0c\u5177\u4f53\u539f\u56e0\u662f\u5176\u8d85\u51fa\u4e86\u6700\u59276\u6b21\u8f93\u5165\u9519\u8bef\u5bc6\u7801\u7684\u9650\u5236 \u3002<\/p>\n
3\u3001pam\u6587\u4ef6\u67e5\u770b<\/strong><\/span><\/div>\n\u67e5\u770bsshd\u670d\u52a1\u7684pam\u914d\u7f6e\u6587\u4ef6\uff0c\u5728\u517611\u884c\u53d1\u73b0\u6709pam_tally\u7684\u7b56\u7565\u914d\u7f6e\uff0c\u5982\u4e0b\uff1a<\/p>\n
www.361way.com:\/var\/log # cat \/etc\/pam.d\/sshd\r\n#%PAM-1.0\r\nauth include common-auth\r\nauth required pam_nologin.so\r\naccount include common-account\r\npassword include common-password\r\nsession include common-session\r\n# Enable the following line to get resmgr support for\r\n# ssh sessions (see \/usr\/share\/doc\/packages\/resmgr\/README)\r\n#session optional pam_resmgr.so fake_ttyname\r\nauth required pam_tally.so deny=6\r\naccount required pam_tally.so\r\n<\/pre>\n\u4e0a\u976211\u884c\u7684\u914d\u7f6e\u6709\u70b9\u9738\u9053\uff0c\u8d85\u8fc76\u6b21\u9519\u8bef\u5bc6\u7801\uff0c\u5c31\u76f4\u63a5\u6c38\u8fdc\u9501\u5b9a\u4e86\uff0c\u9664\u975e\u624b\u5de5\u89e3\u9664 \uff0d\uff0d\uff0d\uff0d \u5b89\u5168\u7ec4\u540c\u4e8b\u7684\u914d\u7f6e\uff0c\u4e0d\u597d\u975e\u8bae \u3002\u5176\u5b9e\u53ef\u4ee5\u8ba9\u5176\u81ea\u52a8\u8fc7\u4e00\u6bb5\u65f6\u95f4\u89e3\u9664\u9650\u5236\u7684\uff0c\u7f51\u4e0a\u7ecf\u5e38\u770b\u5230\u914d\u6cd5\u5982\u4e0b\uff1a<\/p>\n
auth required pam_tally.so deny=3 unlock_time=300\r\n<\/pre>\n\u4e0a\u9762\u7684\u914d\u7f6e\u8868\u793a\uff0c\u8d85\u8fc73\u6b21\u5931\u8d25\uff0c\u9501\u5b9a300\u79d2 \uff0c\u65f6\u95f4\u5230\u4e86\u4ee5\u540e\uff0c\u81ea\u52a8\u89e3\u9664\u9650\u5236\u3002<\/p>\n
\u4e09\u3001\u95ee\u9898\u89e3\u51b3<\/strong><\/div>\n\u65e2\u7136\u627e\u5230\u4e86\u539f\u56e0\uff0c\u6b64\u65f6\u901a\u8fc7\u67e5\u770b\/etc\/shadow\u6587\u4ef6\uff0c\u4f1a\u53d1\u73b0\u4ee5: \u5206\u9694\u7684\u7b2c\u4e8c\u4f8b\u52a0\u5bc6\u540e\u7684\u5bc6\u7801\u4e32\u90e8\u5206\u524d\u9762\u4f1a\u6709\u4e00\u4e2a\u53f9\u53f7\uff01 \uff0c\u5373\u8868\u793a\u7528\u6237\u88ab\u9501\u5b9a\uff0c\u65e2\u7136\u627e\u5230\u4e86\u539f\u56e0\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u65b9\u6cd5\u89e3\u9501\uff1a<\/p>\n
www.361way.com:\/var\/log # pam_tally --reset --user prestat \/\/prestat\u4e3a\u7528\u6237\u540d\r\nUser prestat (310) had 40\r\n\u6216\r\nfaillog -r\r\n<\/pre>\n\u6ce8\uff1a\u7531\u4e8e\u8be5\u4e3b\u673a\u4f7f\u7528\u7684\u7cfb\u7edf\u7248\u672c\u6709\u4e9b\u8001\uff0c\u4f7f\u7528\u8fd8\u662fpam_tally\u6a21\u5757\uff0c\u5b9e\u9645\u4e0a\u540e\u9762\u4e00\u4e9b\u65b0\u7684\u7cfb\u7edf\u91cc\u5f88\u591a\u5f00\u59cb\u4f7f\u7528pam_tally2\u6a21\u5757\uff0c\u5177\u4f53\u89e3\u9501reset\u6b21\u6570\u4e5f\u53ef\u4ee5\u7b80\u5316\u4e0b\uff1a<\/p>\n
pam_tally2 -r -u \u7528\u6237\u540d\r\n<\/pre>\n\u5176\u4ed6\u62d3\u5c55\uff1a<\/p>\n
\u67e5\u770b\u67d0\u4e00\u7528\u6237\u9519\u8bef\u767b\u9646\u6b21\u6570\uff1a\r\npam_tally --user\r\n\u4f8b\u5982\uff0c\u67e5\u770bwork\u7528\u6237\u7684\u9519\u8bef\u767b\u9646\u6b21\u6570\uff1a\r\npam_tally --user work\r\n\u6e05\u7a7a\u67d0\u4e00\u7528\u6237\u9519\u8bef\u767b\u9646\u6b21\u6570\uff1a\r\npam_tally --user --reset\r\n\u4f8b\u5982\uff0c\u6e05\u7a7a work \u7528\u6237\u7684\u9519\u8bef\u767b\u9646\u6b21\u6570\uff0c\r\npam_tally --user work --reset\r\n<\/pre>\n\u8be5\u6a21\u5757\u7684\u66f4\u591a\u7528\u6cd5\u548c\u4fe1\u606f\u4e5f\u53ef\u4ee5\u901a\u8fc7man pam_tally \u6216 man pam_tally2 \u8fdb\u884c\u67e5\u770b\u3002<\/p>\n
\n\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.361way.com\/ssh-login-deny\/4274.html<\/a><\/p>\n