`
hongtoushizi
  • 浏览: 363376 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

Using SSH agent for sudo authentication

阅读更多

Using SSH agent for sudo authentication

13 March 2011

pam-ssh-agent-auth is a PAM module which allows you to use your SSH keys to authenticate for sudo. If you aren’t happy using completely passwordless sudo but don’t want to be typing passwords all the time this module provides a compromise.

There’s currently no deb package available (and my debian-fu isn’t quite up to creating one yet) but it’s fairly easy to build and configure manually.

1. Download

Grab the the source from SourceForge and extract:

wget "http://downloads.sourceforge.net/project/pamsshagentauth/pam_ssh_agent_auth/v0.9.3/pam_ssh_agent_auth-0.9.3.tar.bz2"
tar -xjvf pam_ssh_agent_auth-0.9.3.tar.bz2
cd pam_ssh_agent_auth-0.9.3

2. Dependencies

As well as the standard build tools (build-essential and checkinstall) you’ll need some header files:

sudo aptitude install libssl-dev libpam0g-dev

3. Build and install

Before building, we need to set a couple of configuration options: By default, the module will try to install itself in /usr/local/libexec whereas Ubuntu keeps its PAM modules in /lib/security. We also need to tell it that the man page is in NROFF format, not plain text.

./configure --libexecdir=/lib/security --with-mantype=man

Now we can build and install:

make
sudo checkinstall

As well as installing, checkinstall will spit out a deb package that you can use on other machines as long as they share the same architecture. (The package won’t include any dependency information but that isn’t required in this case.) It will also allow you to cleanly uninstall via aptitude remove.

4. Configure

Note: At this point, it would be wise to open another terminal and sudo -s to root. Otherwise, if you balls up your sudo/PAM config you won't be able to get sufficient privileges to fix it, whereupon there will be wailing and gnashing of teeth.

We need to make three changes. First, copy your authorized_keys file into/etc/ssh/sudo_authorized_keys:

sudo cp ~/.ssh/authorized_keys /etc/ssh/sudo_authorized_keys

If there are other users who you want to be able to sudo using this mechanism you’ll need to append their authorized_keys to this file as well. It’s important that this file only be writable by root to prevent users just writing their own keys into this file and then using those to authenticate against.

Secondly, ensure that sudo passes on the SSH_AUTH_SOCK environment variable so PAM knows how to talk to your key agent. Edit your sudoers file (use visudo for this, it will stop you doing anything stupid) and add the following line:

Defaults env_keep += SSH_AUTH_SOCK

Thirdly, we tell PAM to use this particular module to authenticate for sudo. To do this, edit/etc/pam.d/sudo and add the line beginning auth (the order of these lines is significant):

#%PAM-1.0

auth [success=2 default=ignore] pam_ssh_agent_auth.so file=/etc/ssh/sudo_authorized_keys
@include common-auth
@include common-account

session required pam_permit.so
session required pam_limits.so

We’re configuring the module as follows:

success=2
On a successful authentication, skip the next two config lines i.e., don’t attempt the normal authentication mechanisms.

default=ignore
If anything else happens, carry on as normal so if your key isn’t available or the module breaks for any reason you can still sudo using your password.

file=/etc/ssh/sudo_authorized_keys
The file where the keys which grant sudo rights are stored.

For more details, see the documentation for PAM and pam-ssh-agent-auth (also try man pam_ssh_agent_auth).

5. Test and debug

Test by using sudo -K to force reauthentication:

sudo -K
sudo whoami

You should get the response ‘root’ without being prompted for your password. If not, check that your SSH_AUTH_SOCK is set and being correctly passed though by sudo:

printenv | grep SSH
sudo printenv | grep SSH

You can also add debug to the end of the auth line in pam.d/sudo and get more detailed information logged to /var/log/auth.log

 

转载: http://www.evans.io/posts/ssh-agent-for-sudo-authentication/

分享到:
评论

相关推荐

    ubuntu open ssh 离线安装包

    1.将4个文件放在一个单独的文件夹... sudo gedit /etc/ssh/sshd_config #(可视化编辑器) 修改Port即可 *如果上面已经启动,则不必运行 5、启动ssh sudo systemctl restart ssh sudo systemctl restart sshd

    ubuntu离线安装包ssh-server.zip

    Ubuntu20.04离线安装openssh-server 安装步骤: sudo dpkg -i libssl1.0.0_1.0.2n-1ubuntu5.7_amd64.deb sudo dpkg -i openssh-client_8.4p1-6ubuntu1_amd64.deb sudo dpkg -i openssh-sftp...sudo service ssh restart

    Ubuntu14.04离线安装ssh所需安装包deb

    1.按以下顺序执行安装 ...sudo dpkg -i ssh_6.6p1-2ubuntu1_all.deb 2.安装后输入以下命令:ps -e|grep sshd 若看到sshd,就说明ssh-server已经启动了。 若未启动,尝试以下命令:/etc/init.d/ssh start

    sudo for aix5.3 在aix6.1安装测试通过

    sudo for aix5.3 在aix6.1安装测试通过

    pam_ssh_agent_auth-开源

    PAM模块,允许通过ssh-agent认证任意服务。 考虑到sudo编写,但是像任何auth PAM模块一样,可以用于许多目的。

    乌班图ssh配置过程

    $ sudo /etc/init.d/ssh start 或者: $ sudo /etc/init.d/ssh restart 如果启动服务失败,可以尝试重启虚拟机,然后再次启动服务。如果仍然启动不了,可能是由于版本问题,需要升级系统以解决兼容性问题。 在 ...

    ubuntu14.04 ssh离线安装包

    1.按以下顺序执行安装 ...sudo dpkg -i ssh_6.6p1-2ubuntu1_all.deb 2.安装后输入以下命令:ps -e|grep sshd 若看到sshd,就说明ssh-server已经启动了。 若未启动,尝试以下命令:/etc/init.d/ssh start

    ubuntu 14.04 ssh server离线包

    1.把文件解压 2.一定要按顺序启动 ...sudo dpkg -i ssh_6.6p1-2ubuntu1_all.deb 3.安装后输入以下命令:ps -e|grep sshd 若看到sshd,就说明ssh-server已经启动了。 若未启动,尝试以下命令:/etc/init.d/ssh start

    VScode用ssh连接虚拟机.docx

    sudo service ssh start ``` 3. 启动sshd服务后,VScode可以连接虚拟机了。 VScode使用ssh连接虚拟机可以实现远程开发和调试,提高开发效率。但是,需要注意设置ssh路径和虚拟机配置等注意事项,以确保连接成功。

    sudo1.9.5p2升级

    sudo1.9.5p2升级包及升级命令

    解决mysql登录错误:’Access denied for user ‘root’@’localhost’

    首先是不知道怎么忽然mysql用命令行,workbench都登录不了,都提示’Access denied for user ‘root’@’localhost’。 数据库卸载重装了几次都不行。好像感觉数据清理不干净。解决的过程遇到的坑,这里记录分享下。...

    su和sudo的区别

    从细节上给你讲解su和sudo的区别, 1 就是说从sudo切入进去的root并不是真正的root,而是具有root的某方面权限而已.. 也就是说 从sudo切入进去的,跟输入root 再输入密码的.两种情况权限可能不相同的...对吗...

    centos6-sudo-1.9.9.rpm包;修复CVE-2021-3156,Sudo堆缓冲区溢出漏洞

    此为centos6版的最新sudo-1.9.9.rpm包,修复修复CVE-2021-3156漏洞。 升级步骤: 1、将RPM包上传到服务器上, 2、执行升级命令: # rpm -Uvh sudo-1.9.9-1.el6.x86_64.rpm 3、执行完毕后,查询sudo版本: # sudo -V

    linux的sudo详解

    sudo.pdf

    SSH远程ubuntu

    在 ssh 服务器中,打开这个配置文件,注意是 sshd_config 文件:$sudo vim /etc/ssh/sshd_config 找到这一行,编辑如下:X11Forwarding yes确保这个是 yes(注意这个配置文件中的#是注释,确保 X11Forwarding 前面...

    ubuntu20.04离线安装ssh-server安装包

    sudo dpkg -i libssl1.0.0_1.0.2n-1ubuntu5.7_amd64.deb sudo dpkg -i openssh-client_8.4p1-6ubuntu1_amd64.deb sudo dpkg -i openssh-sftp-server_8.4p1-6ubuntu1_amd64....sudo dpkg -i ssh_8.4p1-6ubuntu1_all.deb

    centos7-sudo-1.9.9.rpm包。修复CVE-2021-3156,Sudo堆缓冲区溢出漏洞

    此为centos7版的最新sudo-1.9.9.rpm包,修复修复CVE-2021-3156漏洞。 升级步骤: 1、将RPM包上传到服务器上, 2、执行升级命令: # rpm -Uvh sudo-1.9.9-1.el7.x86_64.rpm 3、执行完毕后,查询sudo版本: # sudo -V

    Debian如何限制sudo权限

    能学到什么:设置普通用户执行sudo的权限,使其只能执行指定的命令。 用户使用su命令切换root。但是权限太大,而且root密码有泄露风险。那么能否在不泄露root密码的前提下对权限进行限制呢?答案就是用sudo。 sudo...

Global site tag (gtag.js) - Google Analytics