「SCP と SFTP」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(関連記事)
(→‎Secure file transfer protocol (SFTP): add == Secure file transfer protocol (SFTP) with a chroot jail ==)
21行目: 21行目:
   
 
''sftp'' プログラムや [[sshfs]] を使ってファイルを操作できるはずです。標準的な FTP プログラムも大抵は動作します。
 
''sftp'' プログラムや [[sshfs]] を使ってファイルを操作できるはずです。標準的な FTP プログラムも大抵は動作します。
  +
  +
== Secure file transfer protocol (SFTP) with a chroot jail ==
  +
  +
Sysadmins can jail a subset of users to a chroot jail using {{Pkg|openssh}} thus restricting their access to a particular directory tree. This can be useful to simply share some files without granting full system access or shell access. Users with this type of setup may use SFTP clients such as {{Pkg|filezilla}} to put/get files in the chroot jail.
  +
  +
=== Setup the filesystem ===
  +
  +
Create a jail directory:
  +
  +
# mkdir -p /var/lib/jail
  +
  +
Optionally, bind mount the filesystem to be shared to this directory. In this example, {{ic|/mnt/data/share}} is to be used. It is owned by root and has octal permissions of 755.
  +
  +
# mount -o bind /mnt/data/share /var/lib/jail
  +
  +
{{Tip|Consider adding an entry to {{ic|/etc/fstab}} to make the bind mount survive a reboot.}}
  +
  +
=== Create an unprivileged user ===
  +
  +
Create the share user and setup a good password:
  +
  +
# useradd -g sshusers -d /var/lib/jail foo
  +
# passwd foo
  +
  +
=== Setup OpenSSH ===
  +
  +
Add the following to the end of {{ic|/etc/ssh/sshd_config}} to enable the share and to enforce the restrictions:
  +
  +
{{hc|/etc/ssh/sshd_config|
  +
...
  +
Match group sshusers
  +
ChrootDirectory %h
  +
X11Forwarding no
  +
AllowTcpForwarding no
  +
PasswordAuthentication yes
  +
ForceCommand internal-sftp
  +
}}
  +
  +
[[Restart]] {{ic|sshd.service}} to re-read the configuration file. See [[SFTP chroot]] to configure the keys correctly when using chroot or it will get permission denied.
  +
  +
Test that in fact, the restrictions are enforced by attempting an ssh connection via the shell. The ssh server should return a polite notice of the setup:
  +
  +
{{hc|$ ssh foo@someserver.com|
  +
foo@someserver.com's password:
  +
This service allows sftp connections only.
  +
Connection to someserver.com closed.
  +
}}
   
 
== Secure copy protocol (SCP) ==
 
== Secure copy protocol (SCP) ==

2022年9月26日 (月) 10:26時点における版

関連記事

Secure copy (SCP)Secure Shell 接続を使ってファイルを転送するプロトコルです。SSH file transfer protocol (SFTP) は同じようなプロトコルで、SCP と同様に Secure Shell をバックエンドとして使います。どちらのプロトコルでもパスワードや転送データが暗号化されるので、安全にファイルを転送できます。ただし、SFTP プロトコルには、中断した転送の再開やリモートのファイルを削除したりする機能が追加されています。

Secure file transfer protocol (SFTP)

OpenSSH をインストール・設定するだけで SFTP のセットアップも完了しています。SSH が動作しているのであれば、SSH のデフォルト設定で有効になっているので SFTP も同じく動作しています。設定が古い場合は以下の手順に従ってください。

適当なエディタで /etc/ssh/sshd_config を開いて、以下の行を (存在しない場合) 追加してください:

Subsystem sftp /usr/lib/ssh/sftp-server

sshd.service デーモンを再起動すれば SFTP が機能します。

sftp プログラムや sshfs を使ってファイルを操作できるはずです。標準的な FTP プログラムも大抵は動作します。

Secure file transfer protocol (SFTP) with a chroot jail

Sysadmins can jail a subset of users to a chroot jail using openssh thus restricting their access to a particular directory tree. This can be useful to simply share some files without granting full system access or shell access. Users with this type of setup may use SFTP clients such as filezilla to put/get files in the chroot jail.

Setup the filesystem

Create a jail directory:

# mkdir -p /var/lib/jail

Optionally, bind mount the filesystem to be shared to this directory. In this example, /mnt/data/share is to be used. It is owned by root and has octal permissions of 755.

# mount -o bind /mnt/data/share /var/lib/jail
ヒント: Consider adding an entry to /etc/fstab to make the bind mount survive a reboot.

Create an unprivileged user

Create the share user and setup a good password:

# useradd -g sshusers -d /var/lib/jail foo
# passwd foo

Setup OpenSSH

Add the following to the end of /etc/ssh/sshd_config to enable the share and to enforce the restrictions:

/etc/ssh/sshd_config
...
 Match group sshusers
  ChrootDirectory %h
  X11Forwarding no
  AllowTcpForwarding no
  PasswordAuthentication yes
  ForceCommand internal-sftp

Restart sshd.service to re-read the configuration file. See SFTP chroot to configure the keys correctly when using chroot or it will get permission denied.

Test that in fact, the restrictions are enforced by attempting an ssh connection via the shell. The ssh server should return a polite notice of the setup:

$ ssh foo@someserver.com
foo@someserver.com's password:
This service allows sftp connections only.
Connection to someserver.com closed.

Secure copy protocol (SCP)

opensshインストール・設定して起動してください。パッケージにはファイルを転送するための scp コマンドが含まれています。詳しくは Secure Shell を参照。

rsshAURscponly などのパッケージをインストールすることでさらに機能を追加できます。下を参照。

Scponly

Scponly は scp/sftp だけでしかコンピュータにアクセスできないようにする制限的なシェルです。さらに、scponly で特定のディレクトリに chroot をセットアップして更にセキュリティを高めることもできます。

scponlyインストールしてください。

既にユーザーを作成している場合、ユーザーのシェルを scponly に設定するだけです:

# usermod -s /usr/bin/scponly username

これで完了です。適当な sftp クライアントを使用してテストしてみてください。

chroot 監獄の追加

パッケージには chroot を作成するスクリプトが付属しています。使用するには:

# /usr/share/doc/scponly/setup_chroot.sh
  • 質問に答えてください。
  • /path/to/chroot の所有者を root:root にして others の権限を r-x にします。
  • 使用するユーザーのシェルを /usr/bin/scponlyc に変更します。
  • sftp-server は libnss_files などの libnss モジュールを必要とします。モジュールを chroot の /lib パスにコピーしてください。