<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>深度VPS &#187; 安全登录</title>
	<atom:link href="http://www.deepvps.com/tag/%E5%AE%89%E5%85%A8%E7%99%BB%E5%BD%95/feed" rel="self" type="application/rss+xml" />
	<link>http://www.deepvps.com</link>
	<description>专注VPS技术，关注前端技术</description>
	<lastBuildDate>Sat, 04 Feb 2023 14:00:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>用 root 安全登录 VPS 的方法</title>
		<link>http://www.deepvps.com/two-methods-to-secure-root-access.html</link>
		<comments>http://www.deepvps.com/two-methods-to-secure-root-access.html#comments</comments>
		<pubDate>Thu, 02 Dec 2010 14:38:49 +0000</pubDate>
		<dc:creator>deepvps</dc:creator>
				<category><![CDATA[VPS管理维护]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[安全登录]]></category>

		<guid isPermaLink="false">http://www.deepvps.com/?p=667</guid>
		<description><![CDATA[VPS 好比一个 Internet 上的独立服务器，有 root 权限，有独立 IP，完全暴露在 Internet上，所以用 root 登录 VPS 操作时要特别注意安全问题，这年头无聊的人太多了，如果你对安全问题还有犹豫，抱有“我这个小站没人理”的想法，那么打开 /var/log/secure 看看有多少 IP 多少次企图登录你的服务器？
刚开通的一个 VPS 还来不及用，过几天打开 /var/log/secure 一看，发现 n 个 IP 访问了 n 次。一个 IP 地址为 213.115.115.113 的机器1天内2600多次猜测用户名/密码企图登录。
这是 log 文件片段：
Jun 28 13:49:23 blog sshd[3462]: Received disconnect from 213.115.115.113: 11: Bye Bye
Jun 28 13:49:24 blog sshd[3695]: Invalid user radu from 213.115.115.113
Jun 28 13:49:24 blog [...]]]></description>
			<content:encoded><![CDATA[<p>VPS 好比一个 Internet 上的独立服务器，有 root 权限，有独立 IP，完全暴露在 Internet上，所以用 root 登录 VPS 操作时要特别注意安全问题，这年头无聊的人太多了，如果你对安全问题还有犹豫，抱有“我这个小站没人理”的想法，那么打开 /var/log/secure 看看有多少 IP 多少次企图登录你的服务器？</p>
<p>刚开通的一个 VPS 还来不及用，过几天打开 /var/log/secure 一看，发现 n 个 IP 访问了 n 次。一个 IP 地址为 213.115.115.113 的机器1天内2600多次猜测用户名/密码企图登录。<br />
<span id="more-667"></span>这是 log 文件片段：</p>
<blockquote><p>Jun 28 13:49:23 blog sshd[3462]: Received disconnect from 213.115.115.113: 11: Bye Bye<br />
Jun 28 13:49:24 blog sshd[3695]: Invalid user radu from 213.115.115.113<br />
Jun 28 13:49:24 blog sshd[3703]: input_userauth_request: invalid user radu<br />
Jun 28 13:49:24 blog sshd[3695]: pam_unix(sshd:auth): check pass; user unknown<br />
Jun 28 13:49:24 blog sshd[3695]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=static-213-115-115-113.sme.bredbandsbolaget.se<br />
Jun 28 13:49:26 blog sshd[3695]: Failed password for invalid user radu from 213.115.115.113 port 51310 ssh2<br />
Jun 28 13:49:26 blog sshd[3703]: Received disconnect from 213.115.115.113: 11: Bye Bye<br />
Jun 28 13:49:27 blog sshd[3910]: Invalid user raducu from 213.115.115.113<br />
Jun 28 13:49:27 blog sshd[3921]: input_userauth_request: invalid user raducu<br />
Jun 28 13:49:27 blog sshd[3910]: pam_unix(sshd:auth): check pass; user unknown<br />
Jun 28 13:49:27 blog sshd[3910]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=static-213-115-115-113.sme.bredbandsbolaget.se<br />
Jun 28 13:49:30 blog sshd[3910]: Failed password for invalid user raducu from 213.115.115.113 port 52740 ssh2<br />
Jun 28 13:49:30 blog sshd[3921]: Received disconnect from 213.115.115.113: 11: Bye Bye<br />
Jun 28 13:49:31 blog sshd[5280]: Invalid user raul from 213.115.115.113<br />
Jun 28 13:49:31 blog sshd[5293]: input_userauth_request: invalid user raul<br />
Jun 28 13:49:31 blog sshd[5280]: pam_unix(sshd:auth): check pass; user unknown<br />
Jun 28 13:49:31 blog sshd[5280]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=static-213-115-115-113.sme.bredbandsbolaget.se<br />
Jun 28 13:49:33 blog sshd[5280]: Failed password for invalid user raul from 213.115.115.113 port 54742 ssh2<br />
Jun 28 13:49:34 blog sshd[5293]: Received disconnect from 213.115.115.113: 11: Bye Bye<br />
Jun 28 13:49:35 blog sshd[5540]: Invalid user robert from 213.115.115.113<br />
Jun 28 13:49:35 blog sshd[5570]: input_userauth_request: invalid user robert<br />
Jun 28 13:49:35 blog sshd[5540]: pam_unix(sshd:auth): check pass; user unknown<br />
Jun 28 13:49:35 blog sshd[5540]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=static-213-115-115-113.sme.bredbandsbolaget.se<br />
Jun 28 13:49:37 blog sshd[5540]: Failed password for invalid user robert from 213.115.115.113 port 56483 ssh2</p></blockquote>
<p>所以安全问题不可小觑。有2种方式可以增加 root 登录 VPS 时的安全性，这2种方式绑在一起用最好，如果怕麻烦的话至少要用其中的1种。</p>
<h3>禁止 root 直接登录 sshd</h3>
<p>登录VPS时必须用一个普通帐号登录，然后 su 成 root。可以修改 /etc/ssh/sshd_config 来禁止 root 直接登录：</p>
<pre>PermitRootLogin no</pre>
<h3>启用 SSH Keys 登录</h3>
<p>这种方法虽然不允许 root 用输入密码的方式直接登录 ssh，但是可以通过使用一对 ssh public/private key 来登录。配置步骤如下：</p>
<p>1、在客户端运行下面的命令，创建一对 public/private key：</p>
<pre>ssh-keygen -t dsa</pre>
<p>按照提示，上面的命令会创建2个文件：id_dsa 和 id_dsa.pub，前一个是 private key，后一个是 public key。创建key的时候会提示输入 passphrase，相当于密码一样的东西，用来保护 private key不被滥用。</p>
<p>2、保护好生成的 private key，不要让外界访问到。</p>
<p>3、在你要访问的服务器上创建一个 /root/.ssh/authorized_keys 文件，把生成的 publice key（id_dsa.pub）的内容 copy+paste 到 authorized_keys 里，注意小心完整的 copy，不要有空格/空行。</p>
<p>4、禁止 root 用输入密码的方式直接登录 sshd，修改 /etc/ssh/sshd_config，加上/修改这一行：</p>
<pre>PermitRootLogin without-password</pre>
<h3>重启 sshd</h3>
<pre>/etc/init.d/sshd restart</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.deepvps.com/two-methods-to-secure-root-access.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
