AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 504741
Accepted
Julien
Julien
Asked: 2013-05-04 03:32:00 +0800 CST2013-05-04 03:32:00 +0800 CST 2013-05-04 03:32:00 +0800 CST

宽容模式下的 Selinux,基于 ssh 密钥的身份验证和锁定帐户

  • 772

我注意到在宽容模式下,基于 ssh 密钥的登录和 selinux 有一些奇怪的地方。

让我向您介绍设置:服务器是更新的 Centos 6.4 x86_64。

我们创建没有密码的用户(然后用户将被锁定):

# useradd testuser
# passwd -S testuser
testuser LK 2013-05-03 0 99999 7 -1 (Password locked.)

然后我们设置 ssh 密钥:

# install -d -m 700 -o testuser -g testuser /home/testuser/.ssh/
# install -m 600 -o testuser -g testuser /root/.ssh/id_rsa.pub /home/testuser/.ssh/authorized_keys

让我们检查一下selinux状态

# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

然后让我们尝试以 testuser 身份登录:

# ssh testuser@localhost
Last login: Fri May  3 13:26:32 2013 from ::1
$

有用 !现在我们将 Selinux 设置为宽容模式

# setenforce 0
# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   permissive
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

我们再次尝试登录:

# ssh testuser@localhost
testuser@localhost's password:

SSH 不接受密钥并要求输入密码!

问题:那是一个错误吗?

编辑:在 restorecon -Rv /home 之后,我有

$ ls -laZ ~/.ssh/
drwx------. user wheel unconfined_u:object_r:ssh_home_t:s0 ./
drwxr-x---. user wheel unconfined_u:object_r:user_home_dir_t:s0 ../
-rw-------. user wheel system_u:object_r:ssh_home_t:s0  authorized_keys

$ getsebool -a | grep 'ssh'
allow_ssh_keysign --> off
fenced_can_ssh --> off
ssh_chroot_full_access --> off
ssh_chroot_manage_apache_content --> off
ssh_chroot_rw_homedirs --> off
ssh_sysadm_login --> off

编辑:这是 /var/log/secure 的内容

Jun 13 16:30:51 dhcp-240 sshd[13681]: User testuser not allowed because account is locked
Jun 13 16:30:51 dhcp-240 sshd[13682]: input_userauth_request: invalid user testuser
centos6
  • 2 2 个回答
  • 7334 Views

2 个回答

  • Voted
  1. Best Answer
    Julien
    2013-07-13T02:30:38+08:002013-07-13T02:30:38+08:00

    所以,我发现了问题。看来确实是配置问题。

    如果 sshd_config 包含该指令UsePAM no,则 ssh 守护程序不接受用户密钥并要求输入密码。

    通过UsePAM yes密钥登录在所有情况下都有效(SELINUX 允许或强制,用户帐户是否锁定)

    • 1
  2. tgharold
    2013-06-03T14:50:58+08:002013-06-03T14:50:58+08:00

    我相信这与 SELinux 无关,而与将模式 644 放在 ~/.ssh/authorized_keys 文件上有关。~/.ssh 目录本身的模式应为 700,该目录中的文件应为模式 600。

    根据OpenSSH 常见问题:

    3.14 - 我将我的公钥复制到 authorized_keys 但公钥身份验证仍然不起作用。

    这通常是由于 $HOME、$HOME/.ssh 或 $HOME/.ssh/authorized_keys 的文件权限比 sshd 默认允许的更宽松。

    这种情况可以通过在服务器上执行以下命令来解决。

    $ chmod go-w $HOME $HOME/.ssh
    $ chmod 600 $HOME/.ssh/authorized_keys
    $ chown `whoami` $HOME/.ssh/authorized_keys
    

    如果由于某种原因无法做到这一点,另一种方法是在 sshd_config 中将 StrictModes 设置为 no,但不推荐这样做。

    您可能还需要执行“restorecon -Rv /root”和“restorecon -Rv /home”。使用“ls -lZ”查看目录所有权和 SELinux 标签。

    • -1

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve