Junyangz's docs
  • Introduction
  • Ops
    • Linux-tips
    • MySQL-5.7.20
    • Upgrading MySQL
    • Upgrade OpenSSH to 7.7p1 in CentOS 6
    • Linux PERSISTENT NAMING
    • Use Kafka with Flume - CRS2
    • Setup Chroot SFTP in CentOS
    • Setup software RAID-5 in CentOS
    • SSH-port-forwarding
    • Elasticsearch In Production
    • ELK-simple-tutorial
    • Ansible Playbooks for Apache Kafka in production
    • GitHub Actions depoly Hexo
    • Test HTTP3/QUIC docker
    • Docker tutorial
    • SFTP-auth-pubkey
    • Linux Process Substitution
  • Note
    • Interview
      • interview-prepare
      • 2020-campus-recruiting
    • Android Tips
    • MacOS tips
    • Secret knowledge
    • GPG-Note
    • ud185
    • ud185-2
    • Introducing Tensorflow Federated
    • Tensorflow Federated
    • Expert Python Programing
    • What happens when zh_CN
    • TILGC
    • VScode keyboard shortcuts
    • Abseil Python
    • Latex Note
    • Git Cheatsheet
    • Study Smarter Not Harder
    • Machine Learning Interviews
    • 深度学习中的优化
    • Beej's Guide to Network Programming Note
      • ch4
      • ch5
      • ch6
      • ch7
  • [Share]
    • What to do after what to do
    • Truman is everywhere
    • Way2outer
    • 未来十五年
  • Quote
Powered by GitBook
On this page

Was this helpful?

  1. Ops

SFTP-auth-pubkey

PreviousDocker tutorialNextLinux Process Substitution

Last updated 2 years ago

Was this helpful?

现有两台主机A、B。主机A使用用户名sftp-users通过sftp登录主机B上传文件。

配置公钥登录可以按照如下流程来操作:

  1. 主机A生成公私钥对id_rsa、id_rsa.pub |可用命令ssh-keygen -t rsa生成

  2. 主机B在sftp-users用户的主页目录下创建~/.ssh/authorized_keys文件

  3. 主机B将主机A生成的id_rsa.pub的内容拷贝到上诉文件中,并将authorized_keys文件owner属性设定为sftp-users,权限设定为600。|可以尝试使用 ssh-copy-id进行密钥拷贝。

  4. 主机A使用命令sftp登录主机B进行测试。

如果设定为仅密钥登录,主机B则可以在sshd_config配置文件中屏蔽密码登录:

PasswordAuthentication yes

Match Group sftpusers
        ChrootDirectory /sftp/%u
        PasswordAuthentication no

使用Match Group可让某些选项只对该用户组生效,上诉配置设定了除了sftpusers用户组外,其他用户都可以用密码登录。

Debug小注解:如果使用公钥登录失败首先查看sftp-users的home目录是否设定正确,可通过/etc/passwd查看,如不正确可使用usermod -d /sftp/sftpusers/home sftpusers修改,必须要保证.ssh/authorized_keys的上级目录为sftp-users的home目录。示例中的认证文件绝对路径为/sftp/sftpusers/home/.ssh/authorized_keys

参考文档:

https://wiki.archlinux.org/index.php/SFTP_chroot