<?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>system upgrade &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/tag/system-upgrade/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Mon, 27 Apr 2020 18:04:57 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[原创] 树莓派Arch Linux ARM系统更新后无法ssh登录的故障排查</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%a0%91%e8%8e%93%e6%b4%bearch-linux-arm%e7%b3%bb%e7%bb%9f%e6%9b%b4%e6%96%b0%e5%90%8e%e6%97%a0%e6%b3%95ssh%e7%99%bb%e5%bd%95%e7%9a%84%e6%95%85%e9%9a%9c%e6%8e%92%e6%9f%a5/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%a0%91%e8%8e%93%e6%b4%bearch-linux-arm%e7%b3%bb%e7%bb%9f%e6%9b%b4%e6%96%b0%e5%90%8e%e6%97%a0%e6%b3%95ssh%e7%99%bb%e5%bd%95%e7%9a%84%e6%95%85%e9%9a%9c%e6%8e%92%e6%9f%a5/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sun, 16 Aug 2015 08:38:53 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Raspberry Pi/树莓派]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[/etc/shadow]]></category>
		<category><![CDATA[Permission denied]]></category>
		<category><![CDATA[PermitRootLogin]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[root login]]></category>
		<category><![CDATA[system upgrade]]></category>
		<category><![CDATA[树莓派]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=8522</guid>

					<description><![CDATA[<p>
本来用得好好的树莓派（Arch Linux ARM），没啥事随手打了一条系统更新的命令：</p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
pacman -Syu
</pre>
<p>结果重启之后无法用ssh以root用户登录树莓派了，提示错误如下：</p>
<blockquote>
<p>
		Permission denied, please try again</p>
</blockquote>
<p>这分明就像是密码错误导致的嘛！<br />
<span id="more-8522"></span><br />
一开始，我睁大了眼睛不敢相信，怀疑是密码输错了导致的，但是再三确认之后，情况可以确定了：密码是没错的，但是就是无法登录，试了多个terminal软件都一样，包括Chrome的Secure Shell插件、Ubuntu自带的ssh client，以及PAC。<br />
于是我开始了漫长的问题排查过程。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『1』</span>清除登录用户的登录密码<br />
由于我在树莓派上安装好Arch Linux ARM之后，就一直在家里的内网中使用它，所以也没有特别在意过安全问题，只使用Arch Linux ARM默认的root用户来登录系统（密码是root），因此，我第一个方案想到的就是清除root用户的密码，使得root用户可以无密登录，进了系统以后就一切都好办了。<br />
步骤如下：<br />
把树莓派的TF卡拔下来，接上USB适配器插到一台Ubuntu台式机上，打开<span style="color:#ff0000;">树莓派系统里的</span> <span style="color:#0000ff;">/etc/shadow</span> 文件（该文件保存了用户的登录密码），看到第一行内容类似于：</p>
<pre class="brush:plain;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
root:$6$4kB8D9Mu9$Laa9KKeD/vzCmyyQixAb.Hka...:16450::::::
</pre>
<p>为了安全，当今Linux系统并不是将密码直接保存在 /etc/passwd 文件中（因为该文件是非root用户也可以读取的），而是保存在 <span style="color:#0000ff;">/etc/shadow</span> 文件中，并且密码也不是明文的，而是加密过的&#8212;&#8212;正如大家上面看到的例子一样。<br />
<span style="color:#0000ff;">/etc/shadow</span> 文件的每一行一共有9个字段，每两个字段之间用分号（:）隔开，解释一下几个主要字段的含义：<br />
* 第1个字段：用户名（例如root）<br />
* 第2个字段：用户密码。这个字段最为复杂，里面又以 <span style="color:#ff0000;">$</span> 符号为分隔符，分隔成了几个子字段：<br />
<span style="color:#008000;">6</span>&#160;密码加密方式，6表示密码是使用 SHA-512 算法加密的，这一点从 <span style="color:#0000ff;">/etc/login.defs</span>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%a0%91%e8%8e%93%e6%b4%bearch-linux-arm%e7%b3%bb%e7%bb%9f%e6%9b%b4%e6%96%b0%e5%90%8e%e6%97%a0%e6%b3%95ssh%e7%99%bb%e5%bd%95%e7%9a%84%e6%95%85%e9%9a%9c%e6%8e%92%e6%9f%a5/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
本来用得好好的树莓派（Arch Linux ARM），没啥事随手打了一条系统更新的命令：</p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
pacman -Syu
</pre>
<p>结果重启之后无法用ssh以root用户登录树莓派了，提示错误如下：</p>
<blockquote>
<p>
		Permission denied, please try again</p>
</blockquote>
<p>这分明就像是密码错误导致的嘛！<br />
<span id="more-8522"></span><br />
一开始，我睁大了眼睛不敢相信，怀疑是密码输错了导致的，但是再三确认之后，情况可以确定了：密码是没错的，但是就是无法登录，试了多个terminal软件都一样，包括Chrome的Secure Shell插件、Ubuntu自带的ssh client，以及PAC。<br />
于是我开始了漫长的问题排查过程。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『1』</span>清除登录用户的登录密码<br />
由于我在树莓派上安装好Arch Linux ARM之后，就一直在家里的内网中使用它，所以也没有特别在意过安全问题，只使用Arch Linux ARM默认的root用户来登录系统（密码是root），因此，我第一个方案想到的就是清除root用户的密码，使得root用户可以无密登录，进了系统以后就一切都好办了。<br />
步骤如下：<br />
把树莓派的TF卡拔下来，接上USB适配器插到一台Ubuntu台式机上，打开<span style="color:#ff0000;">树莓派系统里的</span> <span style="color:#0000ff;">/etc/shadow</span> 文件（该文件保存了用户的登录密码），看到第一行内容类似于：</p>
<pre class="brush:plain;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
root:$6$4kB8D9Mu9$Laa9KKeD/vzCmyyQixAb.Hka...:16450::::::
</pre>
<p>为了安全，当今Linux系统并不是将密码直接保存在 /etc/passwd 文件中（因为该文件是非root用户也可以读取的），而是保存在 <span style="color:#0000ff;">/etc/shadow</span> 文件中，并且密码也不是明文的，而是加密过的&mdash;&mdash;正如大家上面看到的例子一样。<br />
<span style="color:#0000ff;">/etc/shadow</span> 文件的每一行一共有9个字段，每两个字段之间用分号（:）隔开，解释一下几个主要字段的含义：<br />
* 第1个字段：用户名（例如root）<br />
* 第2个字段：用户密码。这个字段最为复杂，里面又以 <span style="color:#ff0000;">$</span> 符号为分隔符，分隔成了几个子字段：<br />
<span style="color:#008000;">6</span>&nbsp;密码加密方式，6表示密码是使用 SHA-512 算法加密的，这一点从 <span style="color:#0000ff;">/etc/login.defs</span> 文件中定义的下面这一行也可以证实：</p>
<div>
<pre class="brush:plain;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
ENCRYPT_METHOD  SHA512
</pre>
<p>	还有其他很多加密方式，大家可以用&nbsp;<span style="color:#b22222;">man 3 crypt</span>&nbsp;命令查看一个列表，这里摘抄关键内容如下：</p>
<pre class="brush:plain;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
ID  | Method
────────────────────────────────
1   | MD5
2a  | Blowfish (not in mainline glibc; added in some Linux distributions)
5   | SHA-256 (since glibc 2.7)
6   | SHA-512 (since glibc 2.7)
</pre>
</div>
<p>总之，使用&nbsp;SHA-512 是相对来说最安全的，不要试图改变它。<br />
<span style="color:#008000;">4kB8D9Mu9</span>：一个在生成密码的时候，随机生成的salt字符串，用于增大<a href="https://zh.wikipedia.org/wiki/%E5%BD%A9%E8%99%B9%E8%A1%A8" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">彩虹表</span></a>攻击（破解用户密码）的难度。<br />
<span style="color:#008000;">Laa9KKeD/vzCmyyQixAb.Hka...</span>：加密后的密码。这个字符串很长，所以我这里没有写完，最后用省略号省略了一部分内容。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
从第3个字段起，不是我需要关注的内容，所以这里就不解释了。<br />
要删除root用户的密码，只需要把第1个和第2个冒号之间的那一段内容全部删掉就可以了，变成这样：</p>
<pre class="brush:plain;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
root::16450::::::
</pre>
<p>于是赶紧把TF卡插回树莓派上，启动树莓派，再用root用户登录，依然提示要输密码！直接回车，没用！依然提示&nbsp;Permission denied。<br />
所以这条路是走不通了。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『2』</span>修改root用户的登录密码，而不是删除它<br />
删除root用户的登录密码没用，那我改一个总行了吧？<br />
于是还是找到莓派TF卡上的 <span style="color:#0000ff;">/etc/shadow</span> 文件，这回还是折腾root用户的密码字段，只不过，这一次，我们需要知道如何修改它的密码。<br />
怎样才能生成一个 <span style="color:#0000ff;">/etc/shadow</span> 文件认可的密码字段字符串呢？<br />
答案是使用&nbsp;<span style="color:#ff0000;">mkpasswd</span> 工具。</p>
<div>
	mkpasswd 工具是 whois 这个软件包的一部分，所以要先安装 whois 软件包：</div>
<div>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
sudo apt-get install whois
</pre>
</div>
<div>
	使用命令：</div>
<div>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
mkpasswd -m sha-512
</pre>
</div>
<div>
	然后按提示输入一个明文密码之后，就会生成一个符合 <span style="color: rgb(0, 0, 255);">/etc/shadow</span> 文件要求的密码字段字符串了（$6$...），再把它填到 <span style="color: rgb(0, 0, 255);">/etc/shadow</span> 文件中。</div>
<div>
	把TF卡插回树莓派上，启动树莓派，用root用户登录，依然无效，还提示Permission denied。<br />
	这回我信了，真的不是删密码、改密码可以解决的，一定是有其他什么问题。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	<span style="background-color:#00ff00;">『3』</span>OpenSSH更新引起的惨案<br />
	我乖乖地跑到Arch的坛子上问了大侠们，很快就有人给出了正确的解答：是<a href="http://lists.mindrot.org/pipermail/openssh-unix-announce/2015-August/000122.html" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">OpenSSH更新</span></a>引起的：默认情况下，不再允许root用户以密码方式ssh登录！</div>
<blockquote>
<div>
		<span style="color:#b22222;">* The default for the sshd_config(5) PermitRootLogin option has changed from &quot;yes&quot; to &quot;prohibit-password&quot;.</span></div>
</blockquote>
<div>
	于是我再次把树莓派的TF卡插到Ubuntu机器上，编辑其上的 <span style="color:#0000ff;">/etc/ssh/sshd_config</span> 文件，把下面这行的注释取消掉：</p>
<pre class="brush:plain;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
#PermitRootLogin yes
</pre>
<p>	然后再启动树莓派，root可以登录了，一切正常！<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	<span style="background-color:#00ff00;">『4』</span>总结<br />
	其实用root登录是很不好的习惯，我这次就掉坑里了。不说了，我这就建一个新用户去...</p>
<p>	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
</div>

			<!--[syntaxhighlighter]-->
			<!--代码高亮，请勿编辑-->
			<script type="text/javascript" src="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shCore.js"></script><script type="text/javascript" src="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shBrushShell.js"></script>
<script type="text/javascript" src="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shBrushPlain.js"></script>

			<link type="text/css" rel="stylesheet" href="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/styles/shCoreCk.css" />
			<link type="text/css" rel="stylesheet" href="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/styles/shThemeCk.css" />
			<script type="text/javascript">
			SyntaxHighlighter.defaults['class-name']	= '';
			SyntaxHighlighter.defaults['smart-tabs']	= true;
			SyntaxHighlighter.defaults['tab-size']		= 2;
			SyntaxHighlighter.defaults['gutter']		= true;
			SyntaxHighlighter.defaults['quick-code']	= true;
			SyntaxHighlighter.defaults['collapse'] 		= false;
			SyntaxHighlighter.defaults['auto-links']	= true;
			SyntaxHighlighter.defaults['toolbar']		= true;
			SyntaxHighlighter.all();
			</script>
			<!--[/syntaxhighlighter]-->]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%a0%91%e8%8e%93%e6%b4%bearch-linux-arm%e7%b3%bb%e7%bb%9f%e6%9b%b4%e6%96%b0%e5%90%8e%e6%97%a0%e6%b3%95ssh%e7%99%bb%e5%bd%95%e7%9a%84%e6%95%85%e9%9a%9c%e6%8e%92%e6%9f%a5/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
