CONTENTS


Lastmodified 2013-07-16 (火) 16:31:31


Scponly chroot WinSCP がアクセス不能になっていた件

WinSCPでアクセスして、chroot環境でのファイルUPをして貰っていたのが、先日アクセス出来なくなっていたことが発覚。

アクセスログを見ると、

Jul 16 14:50:23 guard sshd[1253]: Accepted keyboard-interactive/pam for root from aaa.bbb.ccc.ddd port 63977 ssh2
Jul 16 14:50:23 guard sshd[1253]: subsystem request for sftp
Jul 16 14:50:27 guard sshd[1259]: Accepted keyboard-interactive/pam for root from aaa.bbb.ccc.ddd port 63947 ssh2
Jul 16 14:50:48 guard sshd[1273]: User testuser not allowed because shell /usr/local/sbin/scponlyc does not exist
Jul 16 14:50:51 guard sshd[1273]: error: PAM: authentication error for illegal user testuser from aaa.bbb.ccc.ddd
Jul 16 14:50:51 guard sshd[1273]: Failed keyboard-interactive/pam for invalid user testuser from aaa.bbb.ccc.ddd port 64060 ssh2
Jul 16 14:50:53 guard sshd[1273]: error: PAM: authentication error for illegal user testuser from aaa.bbb.ccc.ddd
Jul 16 14:50:53 guard sshd[1273]: Failed keyboard-interactive/pam for invalid user testuser from aaa.bbb.ccc.ddd port 64060 ssh2

の様になっていて、何故か /usr/local/sbin/scponlyc does not exist となっている。

はたして、shell/scponly のコンパイルオプションを見てみたところ、chroot WinSCP support のチェックが外れていた。(゜◇゜)ガーン

scponly_config.PNG

cd /usr/ports/shells/scponly/
make rmconfig
portupgrade -f scponly-4.8.20110526_1

scponly userのshellをscponlyにするメモ

既存のhogehogeというユーザのログインシェルをscponlyにするメモ

待避

# cd /home/
# tar cvfzp hogehoge.tar.gz hogehoge

消去

# rmuser hogehoge
Matching password entry:
hogehoge:*:3006:31::0:0:hogehoge:/home/hogehoge:/bin/csh

Is this the entry you wish to remove? yes
Remove user's home directory (/home/hogehoge)? no
Removing user (hogehoge): processes(3) passwd.

Scponly付属のスクリプトでユーザを作る

 # ./setup_chroot.sh
Next we need to set the home directory for this scponly user.
please note that the user's home directory MUST NOT be writeable
by the scponly user. this is important so that the scponly user
cannot subvert the .ssh configuration parameters.

for this reason, a writeable subdirectory will be created that
the scponly user can write into.

-en Username to install [scponly]
hogehoge
-en home directory you wish to set for this user [/home/hogehoge]

-en name of the writeable subdirectory [incoming]
public_html

Your platform (FreeBSD) does not have a platform specific setup script.
This install script will attempt a best guess.
If you perform customizations, please consider sending me your changes.
Look to the templates in build_extras/arch.
- joe at sublimation dot org

please set the password for hogehoge:
Changing local password for hogehoge
New Password:
Retype New Password:
Mismatch; try again, EOF to quit.
New Password:
Retype New Password:
if you experience a warning with winscp regarding groups, please install
the provided hacked out fake groups program into your chroot, like so:
cp groups /home/hogehoge/bin/groups

WinSCP(4.0.4)でログインしようとすると
SFTPプロトコルを初期化できません。SFTPサーバが起動していますか?
でログインできないので、
groups をコピーし、/usr/home/hogehoge/dev/null を作成したたが、NG
WinSCP404でのログは添付ファイル

# cd /home
# mkdir -p hogehoge/dev
# mount -t devfs devfs hogehoge/dev

で接続OK
だが、reboot すると消えてしまうので接続できなくなります。

[FreeBSD-users-jp 89466] Re: chroot 環境での /dev/null の作り方


Subject:  [FreeBSD-users-jp 89466] Re: chroot 環境での /dev/null の作り方 

やまざきです.

みなさんどうもありがとうございます。

06/04/27 に YAMANEKO/Mao<yneko2@xxxxxxxxxxxx> さんは書きました:

> 昔は・・FreeBSD5.x までは・・tarでデバイスを固めたり、
> mknodで好きなところに作ることができたのですが・・FreeBSD6になってからは、
> devfs上じゃないと、デバイスとして働かないようになってしまいました。
> (なぜなんでしょうか・・・不便な仕様・・)
>
> なので、devfsを使いたいところにマウントすると、
> とりあえず実現できますが・・・大量にchroot環境があるような場合、
> 本当に大量にmountするのか??という問題も・・・。

これはデバイス(といいますか環境)をchrootごとに用意するというのが
そもそものchrootの目的なので、大量にmountするしかないと思います.

> mkdir -p $CVSCHROOT/dev
> mount -t devfs devfs $CVSCHROOT/dev

これですと/devの下にあるデバイス全部が作られるようなので、
下記のようにしてみたところうまくいきました。

# . /etc/rc.subr             (rc用のヘルパースクリプトのロード)
# devfs_init_rulesets     (デバイスルールの初期化)
# devfs_rulesets_from_file /etc/defaults/devfs.rules    (デバイスルールのロード)
# devfs_domount $CVSCHROOT/dev devfsrules_unhide_basic (デバイスの結びつけ)

4行目のdevfsrules_unhide_basicは/etc/defaults/devfs.rulesで定義されているルールセットで
/dev/null, zero crypto random urandomを作るためのルールのようです.

ただリブート時に自動的にデバイスを作る方法がまだわかりません.
上記のスクリプトをcvsd.shに加えてもいいんですが、いまいち芸がない感じです.

1.  /etc/defaults/devfs.rulesもしくは/etc/devfs.rulesでルールを作る
2. どっか(/etc/devfs.conf?)でディレクトリと結びつける.

という感じみたいなので、もうちょっと調べてみようと思います.

やまざき
To: FreeBSD-users-jp@jp.FreeBSD.org
Subject: [FreeBSD-users-jp 90988] Re: scponlycについて  
中治@鳥取です。

>>>>> In <46E8878F.1020101@yahoo.co.jp> 
>>>>>   yama <mailinglist0507@yahoo.co.jp> wrote:

> # mount_devfs devfs /usr/data/hoge/dev
 
> したところ問題なく動くようになりました。

> ただ null 以外の必要のないものまでマウントされてしまいますし
> 起動時に毎回 mount_devfs しなければならなりませんが・・・
 
/etc/fstab に
 
devfs /usr/data/hoge/dev devfs rw 0 0

って書いておけば、起動時に毎回 mount_devfs しなくてもよいはずです。


また、「必要のないもの」については、詳しくは知りませんが、devfs(8)によれば、


  ルールサブシステム
    devfs(5) のルールサブシステムは、システム管理者が DEVFS の各ノードの属性
    を変更できるようにするためのものです。 DEVFS マウントポイントにはそれぞれ
    に ``ruleset'' (ルールセット) というルールのリストが関連づけられていま
    す。デバイスドライバが新しいノードを作成する時には、そのノードがユーザラ
    ンドから見えるようになる前にそれぞれのマウントポイントに関連づけられてい
    るルールセットのすべてのルールが適用されます (下記参照) 。これによって、
    管理者がノードの可視性を含めた属性を変更することができるようになっていま
    す。例えば、 jail(2) の /dev にあるすべてのディスクノードを隠すというよう
    なこともできます。
 
なので、/etc/devfs.rulesをうまく書いてやれば、都合よくできるのではないでしょ
うか。
-- 
NAKAJI Hiroyuki (中治 弘行)

Total access 1675:本日 1:昨日 2

Counter: 1675, today: 1, yesterday: 2

添付ファイル: filescponly_config.PNG 598件 [詳細] filedev-null2.txt 409件 [詳細] filedev-null.txt 429件 [詳細] filehogehoge@ww1.smb.net.log 619件 [詳細]

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2013-07-16 (火) 16:31:31