我有一个基于密码的SSH启用的FreeBSD服务器。 我想启用sudo ,但是我不希望潜在的攻击者成为root访问的一个密码。 我目前的解决scheme是使用公共密钥以root身份login(远程密码身份validation已针对root进行禁用),并且我的普通用户不在wheel中,并且未安装sudo 。
在过去,我使用一次性密码进行sudo访问(我可以公开密钥进入系统,但sudo需要一个OTP,并有30分钟的超时时间让我实际上完成工作,而无需重新authentication所有时间)。 这是一个相当大的麻烦,但是,至less与OPIE / S / Key。 使用硬件令牌可能是好的,但在这一点上我没有。
我一直在寻找的东西,可以让我通过代理转发使用SSH公钥validationsudo。 包含在FreeBSD中的pam_ssh似乎没有这样做 – 它只通过查看用户是否可以解密服务器上的私钥来进行身份validation。 我find了pam_ssh_agent_auth ,但是我在其他地方find很less的引用。 现在是0.9,但是我有点犹豫,相信网关根植于一个程序,我找不到很多人实际使用的证据。
所以,我的问题基本上是2:
pam_ssh_agent_auth在野外使用和可靠吗? 你已经通过OTP解决了这个问题(更多的安全性更多),而且我不能评论pam_ssh_agent_auth。 但似乎你真正关心的不是sudo,而是networking级访问。 换句话说,您似乎关心从特定主机或主机授予用户的权限,而不是特定的系统帐户。 如果是这样的话,可以考虑在你的SSH守护进程之前实现一个敲打端口的scheme,这样SSH就只能从特定的IP和知道秘密敲门的人那里访问。 之后,来自已知主机的常规旧公钥authentication应该是足够的。 如果攻击者仍然可以获得shell的访问权限,那么您可能无法胜任。
我能想到的唯一的另一种情况是在受信任的主机上使用ssh代理,当您使用不受信任的networking时,您可以将您的连接退出(因为您在bsdworld中,甚至可以使用监狱你的主机完全一样)。 就我而言,攻击者拥有shell访问权限的任何框都是完全受到攻击的。 他们是否得到根本的信誉完全是没有意义的。 您的努力可能最好花费在防止首次成功入侵。
干杯,-G
迈克尔,
你想达到什么可以通过两种方式来执行:
你发现一个是使用pam_ssh_agent_auth,或者你可能想使用它的“可怜的表弟” :
SSH到本地主机联盟到SSH密钥转发。 在这里的一步一步的指示指向一个Ubuntu服务器,但所有的命令应该是你的FreeBSD,因为它们是OpenSSH本身的function。
1.将密钥添加到ssh-agent:
user@workstation:~$ ssh-add Identity added: /home/user/.ssh/id_rsa (/home/user/.ssh/id_rsa)
2.将密钥复制到目标服务器上的用户帐户
user@workstation:~$ ssh-copy-id destination-server user@destination-server's password: Now try logging into the machine, with "ssh 'destination-server'", and check in: ~/.ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
3.testing基于密钥的login:
user@workstation:~$ ssh -A destination-server Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-10-server x86_64) * Documentation: http://www.ubuntu.com/server/doc Last login: Mon Aug 8 20:38:48 2011 from 192.168.123.123 user@destination-server:~$
4.现在我们将SSH密钥复制到:/root/.ssh/
user@destination-server:~$ sudo cp ~/.ssh/authorized_keys /root/.ssh/ [sudo] password for user: user@destination-server:~$ sudo ls -l /root/.ssh/au* total 4 -rw------- 1 root root 392 2011-08-08 20:44 authorized_keys
5.回到正常的用户生活,我们检查一下SSHvalidation套接字的存在:
$ echo $SSH_AUTH_SOCK /tmp/ssh-bUhwiw3004/agent.3004
6.有趣的时间! 注意:请记住,您的SSHd可能被configuration为拒绝根访问。 记得启用它
user@destination-server:~$ ssh root@localhost Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-10-server x86_64) * Documentation: http://www.ubuntu.com/server/doc Last login: Mon Aug 8 21:07:29 2011 from eedev.local root@destination-server:~# id uid=0(root) gid=0(root) groups=0(root)
7.派对还没有结束……你可以放松一下,使用别名来玩一下设置:
注意:记住SSH和tty的关系往往是麻烦的
user@destination-server:~$ alias sshudo='ssh -4 -t root@localhost' user@destination-server:~$ sshudo id uid=0(root) gid=0(root) groups=0(root) Connection to localhost closed. user@destination-server:~$ sshudo vi /etc/sudoers
瞧!
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-10-server x86_64) * Documentation: http://www.ubuntu.com/server/doc ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "/etc/motd" 4 lines, 114 characters
8.在你走之前…微调它:
user@destination-server:~$ sshudo vi /root/.ssh/authorized_keys
将from="localhost"添加到正在使用的SSH密钥的前面。 这将限制使用该密钥的远程用户访问并进行testing:
user@destination-server:~$ sshudo id user@destination-server:~$ uid=0(root) gid=0(root) groups=0(root) user@destination-server:~$ Connection to localhost closed.
注销并testing限制
user@destination-server:~$ exit Connection to destination-server closed. user@workstation:~$ ssh root@destination-server root@destination-server's password:
希望这可以帮助。