1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

私的サーバー構築日誌:sftpサーバー・Ubuntu 24.04 LTS in MicroServer N54L

Posted at

能書き

私的サーバー構築日誌:仕切り直しからの自宅サーバー構築の続きです。

MicroServer N54L に Ubuntu24.04LTS をインストールしてZFSで使うように設定した我が家のファイルサーバですが、今回は SFTP でファイル共有します。

実は私が所有しているiPhoneで撮影した写真をファイルサーバーに転送したいのですが、PhotoSyncというアプリではSambaには接続できなかったのでした。SFTPなら大丈夫でした。Sambaで接続できない原因は何でしょうね…

参考文献

ユーザー追加

ログイン不可、ホームディレクトリ無しのユーザーです。

sudo useradd -s /usr/sbin/nologin -M jiro

通常のLinuxユーザーとしてパスワードを作成します。

sudo passwd jiro

追加したユーザーの為の共有ディレクトリを用意します。

cd /mnt/tank
sudo mkdir jiro
sudo chown jiro: jiro
sudo chmod 755 jiro

追加したユーザーの sftp 設定

ChrootDirectoryで指定するディレクトリは、オーナーがroot:rootで権限が755でなければならない事に注意します。

cat | sudo tee /etc/ssh/sshd_config.d/user_jiro.conf >/dev/null <<___
Match User jiro
  X11Forwarding no
  AllowTcpForwarding no
  PermitTTY no
  PasswordAuthentication yes
  ForceCommand internal-sftp
  ChrootDirectory /mnt/tank
___

ssh 設定ファイルを作成したらsshを再起動します。sshdではなくてsshのようです。

sudo systemctl restart ssh

確認

普段使いのマシンからsftpコマンドで入ってみます。

クライアント側
sftp jiro@172.16.1.3

通常のFTPコマンドで操作を確認します。

仕舞い

/etcのSubversion登録。

sudo svn st /etc
cd /etc
sudo svn st | grep "^?" | cut -b9- | sudo xargs -I{} find {} -type f -or -type d -or -type l | sudo xargs -rt svn add
sudo svn ci -m"added user 'jiro'"

セキュリティを考えると、ChrootDirectoryはそのユーザーしか存在しないディレクトリを指定すべきです。今回は技術確認の為にお手軽なディレクトリを指定してしまいました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?