I need to setup an scp server. Suppliers will upload files to that server via scp (not sftp). While configuration was easy for sftp, I really struggle with scp. There are some instructions and how-tos for other operating systems on the web. I tried to follow those, but I always receive an error message:
scp phpinfo.php abc@dev.sftpserver.example.org:/subdir/
/home/abc/bin/bash: Permission denied
lost connection
... no further hints in the logs:
Oct 3 23:16:13 ip-10-2-4-121 sshd[30945]: Accepted password for abc from 1.2.3.4 port 57248 ssh2
Oct 3 23:16:13 ip-10-2-4-121 sshd[30945]: pam_unix(sshd:session): session opened for user abc by (uid=0)
Oct 3 23:16:13 ip-10-2-4-121 sshd[30945]: Received disconnect from 1.2.3.4 port 57248:11: disconnected by user [postauth]
Oct 3 23:16:13 ip-10-2-4-121 sshd[30945]: Disconnected from 1.2.3.4 port 57248 [postauth]
Oct 3 23:16:13 ip-10-2-4-121 sshd[30945]: pam_unix(sshd:session): session closed for user abc
My /etc/ssh/sshd_config
has been modified like this:
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp
Match Group sftp
ChrootDirectory %h
# ForceCommand internal-sftp
AllowTcpForwarding no
... I assume that the ForceCommand is not necessary, if I want to allow scp access.
Permissions in the /home
directory:
[root@ip-10-2-4-121 abc]# ls -al /home
total 16
drwxr-xr-x 4 root root 4096 Oct 3 21:42 .
dr-xr-xr-x 25 root root 4096 Oct 3 20:08 ..
drwx------ 9 root root 4096 Oct 3 23:12 abc
drwx------ 4 ec2-user ec2-user 4096 Oct 3 21:43 ec2-user
I have also tried to copy some dependencies, but I did not know how to find out which files have to be copied. https://www.wilderssecurity.com/threads/how-to-copy-only-needed-libraries-to-a-chroot.329486/ gave me a hint, which I have tried out:
cp --parents `ldd /bin/bash | cut -d " " -f 3` /home/abc
cp --parents `ldd /usr/bin/scp | cut -d " " -f 3` /home/abc
cp --parents `ldd /usr/libexec/openssh/sftp-server | cut -d " " -f 3` /home/abc
My directory structure under /home/abc
:
.
├── bin
│ └── bash
├── dev
│ ├── null
│ ├── random
│ ├── tty
│ └── zero
├── etc
│ ├── group
│ ├── ld.so.cache
│ ├── ld.so.conf
│ ├── ld.so.conf.d
│ │ └── kernel-4.9.51-10.52.amzn1.x86_64.conf
│ └── passwd
├── lib
├── lib64
│ ├── ld-linux-x86-64.so.2
│ ├── libcrypto.so.10
│ ├── libcrypt.so.1
│ ├── libc.so.6
│ ├── libdl.so.2
│ ├── libfreebl3.so
│ ├── liblber-2.4.so.2
│ ├── libldap-2.4.so.2
│ ├── libnspr4.so
│ ├── libnss3.so
│ ├── libnssutil3.so
│ ├── libplc4.so
│ ├── libplds4.so
│ ├── libpthread.so.0
│ ├── libresolv.so.2
│ ├── librt.so.1
│ ├── libsasl2.so.2
│ ├── libsmime3.so
│ ├── libssl3.so
│ ├── libtic.so.5
│ ├── libtinfo.so.5
│ ├── libutil.so.1
│ └── libz.so.1
├── subdir
└── usr
├── bin
│ └── scp
├── lib
├── lib64
│ ├── libnss3.so
│ ├── libnssutil3.so
│ ├── libsasl2.so.2
│ ├── libsmime3.so
│ └── libssl3.so
└── libexec
└── openssh
└── sftp-server
I further have modified /etc/passwd
:
...
abc:x:501:501::/home/abc:/home/abc/bin/bash
Any help is greatly appreciated.