在 Amazon EC2 实例中对用户进行 Chroot

在 Amazon EC2 实例中对用户进行 Chroot

我有一台运行 2016.09 版本的 Amazon Linux AMI 机器。我最近创建了一个用户,并且能够使用它的凭证(私钥)进行连接。

该用户旨在由第三方使用,我想限制其对其主目录(或子目录)的访问,以便它不能访问任何其他文件夹(也不能列出任何其他文件夹/文件)。

我认为我确实需要使用位于 /etc/ssh/sshd_config 中的 sshd_config 文件配置某种 chroot 目录。我已经能够修改其内容,使其看起来像以下文本:

#override default of no subsystems
#Subsystem       sftp    /usr/libexec/openssh/sftp-server
Subsystem      sftp    internal-sftp

Match User myuser
       PasswordAuthentication yes
       ChrootDirectory /home/myuser/ftp_folder
       AllowTCPForwarding no
       X11Forwarding no
       ForceCommand internal-sftp

保存更改后,我通过输入 sudo service sshd restart 来重新启动 ssh 服务。

不幸的是,我无法使用这些更改登录(无论是 ssh 还是使用 ftp):

$ ssh -i 'G:\AWS\ec2_keys\myuser.pem' [email protected]    1.amazonaws.com -vvv

Authenticated to ec2-XXXXXX-XX.compute-1.amazonaws.com ([YYY.YYY.YYY.YYY]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting [email protected]
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: send packet: type 1
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t3 r-1 i0/0 o0/0 fd 4/5 cc -1)

Connection to ec2-XXXXXX-XX.compute-1.amazonaws.com closed by remote host.
Connection to ec2-XXXXXX-XX.compute-1.amazonaws.com closed.
Transferred: sent 2328, received 1996 bytes, in 0.0 seconds
Bytes per second: sent 60664.3, received 52012.8
debug1: Exit status -1

我在配置中缺少什么?谢谢!

答案1

我在这里解决了类似的问题: 如何在 Amazon Linux 中使用 scp chroot 账户?

一些想法: - 您可能需要在用户的主目录中具有特定的目录结构,包括文件/etc/passwd和一些库 - 日志文件可能包含更多详细信息

相关内容