如何在sftp连接上执行脚本?

我在我的机器上运行一个ssh服务器,并且限制只有internal-sftp&ChrootDirectory才能访问某些用户的sftp。 我需要的是在用户进行chroot之前执行脚本的一种方法。 实际上,目标是在客户端连接上安装一个encryption的文件系统,然后将其卸载。 Thx提前。

如果你不想破解openssh代码,你必须使用外部的sftp服务器。 如果你这样做是一个简单的事情围绕它的包装。 例如:在sshd_config

 Subsystem sftp /usr/local/bin/sftp-server 

/usr/local/bin/sftp-server

 #!/bin/sh mount_special_fs chroot /my/secret/stuff /usr/libexec/openssh/sftp-server umount_special_fs 

可能sshd包装起来,从inetd启动包装,但是从inted启动sshd是不鼓励的,因为启动速度慢。

您也可以使用pam模块从pamauthentication模块执行脚本。 您可以将其添加到您的pam sshdconfiguration中。 url: http : //linux.die.net/man/5/pam_script