<?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>sshfs &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/sshfs/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Mon, 22 Aug 2022 02:56:50 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>sshfs &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Ubuntu 使用 SSHFS 掛載遠端空間</title>
		<link>https://noter.tw/30/ubuntu-%e4%bd%bf%e7%94%a8-sshfs-%e6%8e%9b%e8%bc%89%e9%81%a0%e7%ab%af%e7%a9%ba%e9%96%93/</link>
					<comments>https://noter.tw/30/ubuntu-%e4%bd%bf%e7%94%a8-sshfs-%e6%8e%9b%e8%bc%89%e9%81%a0%e7%ab%af%e7%a9%ba%e9%96%93/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Thu, 08 Nov 2018 14:55:06 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[sshfs]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[掛載]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=30</guid>

					<description><![CDATA[<p>趁著有空，慢慢把一些文章補齊，這篇要記錄可以掛載遠端空間的方法，很簡單也很實用，小蛙目前的主機上也都有這些設定。 關於掛載(Mount) 有使用過網路芳鄰的網友應該都知道，可以把網芳空間掛載成像是 Z&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/30/ubuntu-%e4%bd%bf%e7%94%a8-sshfs-%e6%8e%9b%e8%bc%89%e9%81%a0%e7%ab%af%e7%a9%ba%e9%96%93/" data-wpel-link="internal">Ubuntu 使用 SSHFS 掛載遠端空間</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>趁著有空，慢慢把一些文章補齊，這篇要記錄可以掛載遠端空間的方法，很簡單也很實用，小蛙目前的主機上也都有這些設定。 </p>



<span id="more-30"></span>



<h2 class="para wp-block-heading">關於掛載(Mount) </h2>



<p>有使用過網路芳鄰的網友應該都知道，可以把網芳空間掛載成像是 Z 槽；或是大家都使用過隨身碟吧！插上隨身碟的時候，OS 把這個外來裝置掛載在系統上(也許是 F 槽)，讓主要的系統可以存取這個裝置中的東西，今天要講的是在 Ubuntu 上透過網路來掛載遠端空間。 </p>



<p>小蛙主機的硬碟只有少得可憐的 20GB ，如果多放幾個檔案跟圖片，加上備份檔案，很快就面臨到硬碟炸裂的狀況，因此小蛙將上述這些東西擺在另外一台主機上，這樣一來主要主機可以使用到這些檔案，但是又不會占用到少少的 20GB SSD，就有點上面提到的，把 USB 隨身碟插進電腦，差別是一個掛載是直接連結本機，另一個則是透過網路掛載。 </p>



<h2 class="para wp-block-heading">使用 sshfs </h2>



<p>在 Ubuntu 要使用 sshfs 相當簡單，只需要 apt-get 就可以直接使用(更多參數看<a rel="noreferrer noopener nofollow external" href="https://linux.die.net/man/1/sshfs" target="_blank" data-wpel-link="external" class="wpel-icon-right">這裡<span class="wpel-icon wpel-image wpel-icon-6"></span></a>)，因為透過 SSH 連到遠端主機，如果沒有設定金鑰的話，總不可能每次連線都要輸入密碼吧！請先參考<a rel="noreferrer noopener" href="https://noter.tw/278/%e7%99%bb%e5%85%a5-ssh-%e5%85%8d%e8%bc%b8%e5%85%a5%e5%b8%b3%e8%99%9f%e5%af%86%e7%a2%bc/" target="_blank" data-wpel-link="internal">登入 Ssh 免輸入帳號密碼</a>，設定完成並且確認 ssh 到遠端主機不用輸入密碼後，再繼續往下走喔！ </p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code"># 安裝 sshfs
apt-get install sshfs
 
# 掛載遠端空間
#sshfs -o nonempty -o allow_other 帳號@主機:要掛載的遠端資料夾 掛載到本機的資料夾
# 以 nginx 帳號透過 ssh 遠端連線到 abc.com.tw 並將 /root/images 掛載到本機的 /root/remote_folder 下使用
sshfs -o nonempty -o allow_other nginx@abc.com.tw:/root/images /root/remote_folder
 
# -o 是增加的屬性，後面接屬性
# nonempty : 如果掛載的本機磁碟非空也沒關係
# allow_other : 預設掛載後只有 root 可以存取，增加這個選項讓其他使用者也可以存取</pre>



<p>小蛙一開始傻傻的，就這樣設定上去，直到有一天要用的時候發現，奇怪，裝置不見了，再掛載一次又好了，才發現還有「斷線」這件事情，當時 Google 出一個方法，可以寫腳本放在 crontab 來做這項檢查(這裡看看就好，先不要照著做) </p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">if mount | grep "/root/images" &gt; /dev/null; then
        echo "/root/images already mounted";
else
        echo "mount /root/images now";
        umount nginx@abc.com.tw:/root/images
        sshfs -o nonempty -o allow_other nginx@abc.com.tw:/root/images /root/remote_folder
fi</pre>



<p>首先我們知道在 command line 下<code>mount</code>可以看到目前所有已掛載的裝置(也可以用<code>df</code>來看目前有哪些裝置)，上面這段腳本在做的事情很簡單，就是檢查<code>mount</code>輸出的文字中有沒有包含我們掛載的字串，如果有的話就寫 log 然後什麼事都不做，如果沒有掛載的話先做 umount 解除掛載，做這件事的原因是為了避免掛載兩次發生問題，之後再做 mount。 </p>



<p>小蛙剛剛 google 了一下發現，sshfs 有一個參數就是 reconnect 啊啊啊！！！根據 <a rel="noreferrer noopener nofollow external" href="https://askubuntu.com/questions/716612/sshfs-auto-reconnect" target="_blank" data-wpel-link="external" class="wpel-icon-right">SSHFS &#8211; auto reconnect<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 提到的方法，斷線的時候 sshfs 就會自己重連囉！真的很方便。 </p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 server:/path/to/mount /path/to/mount</pre>



<h2 class="para wp-block-heading">解除掛載 sshfs</h2>



<p><a href="https://askubuntu.com/questions/1046816/how-to-umount-non-sudo-sshfs-created-directory" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">這篇文章<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 建議使用 <code>fusermount -u /temp/user/harddrive</code></p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLUEaTfCaIk27xsgv9PvkQ-CIg3gs96yzDGTSqf6sge2HqAPDahKkB-gtAm2P4VhKsJTxWKwwU5yIfz7ZFAzFm16PMwQQ7MRf3vIDjtL2kn8tG5RStZxFkf1LKGCqYfG8kSXH6nR410wvCLxm_TZnxqy=w923-h622-no?authuser=1" alt="AM JKLUEaTfCaIk27xsgv9PvkQ CIg3gs96yzDGTSqf6sge2HqAPDahKkB gtAm2P4VhKsJTxWKwwU5yIfz7ZFAzFm16PMwQQ7MRf3vIDjtL2kn8tG5RStZxFkf1LKGCqYfG8kSXH6nR410wvCLxm TZnxqy=w923 h622 no?authuser=1 Ubuntu 使用 SSHFS 掛載遠端空間" title="Ubuntu 使用 SSHFS 掛載遠端空間"></figure></div>


<p></p>



<p></p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/30/ubuntu-%e4%bd%bf%e7%94%a8-sshfs-%e6%8e%9b%e8%bc%89%e9%81%a0%e7%ab%af%e7%a9%ba%e9%96%93/" data-wpel-link="internal">Ubuntu 使用 SSHFS 掛載遠端空間</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/30/ubuntu-%e4%bd%bf%e7%94%a8-sshfs-%e6%8e%9b%e8%bc%89%e9%81%a0%e7%ab%af%e7%a9%ba%e9%96%93/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
