`
hongtoushizi
  • 浏览: 380692 次
  • 性别: 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/

分享到:
评论

相关推荐

    Veeam Agent for Linux and mysql 安装说明

    在IT领域,尤其是在服务器管理和数据保护方面,Veeam Agent for Linux和MySQL的结合使用是至关重要的。Veeam Agent是一款高效的数据备份解决方案,专为Linux操作系统设计,而MySQL是广泛应用的关系型数据库管理系统...

    ubuntu16 离线安装ssh

    sudo systemctl status ssh ``` 如果服务未启动,你可以使用以下命令启动它: ```bash sudo systemctl start ssh ``` 为了确保SSH服务在每次启动时自动启动,执行: ```bash sudo systemctl enable ssh ``` ...

    原生态ubantu无法使用SSH方法整改步骤详情

    sudo service ssh start 或 sudo service ssh start 三、配置 SSH 服务器 在 SSH 服务器启动后,需要配置 SSH 服务器以便可以远程连接。首先,需要在 /etc/ssh/sshd_config 文件中添加以下一行: KexAlgorithms...

    Ubuntu下ssh服务的安装和配置文档

    如果只有 ssh-agent 进程号,那么说明 SSH 服务还没有启动,可以使用以下命令来启动: sudo /etc/init.d/sshd start 安装 SSH 服务 安装 SSH 服务之前,需要更新源,以便安装最新的 SSH 服务。可以使用以下命令来...

    ssh for linux

    4. **防火墙规则**:确保防火墙允许SSH连接,例如,在Ubuntu上,可以运行`sudo ufw allow ssh`开启SSH的端口22。 **三、SSH的使用** 1. **远程登录**:使用`ssh username@hostname`命令登录远程服务器,其中`...

    ubuntu open ssh 离线安装包

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

    ssh for aix6.1

    在提供的压缩包"ssh for aix6.1"中,包含了OpenSSH的相关文件和安装文档。解压该压缩包后,你会找到包含安装步骤的文档,通常包括安装前的系统检查、安装过程以及安装后的配置指南。 1. **系统检查**:在安装...

    ubuntu start SSH service.pdf

    sudo /etc/init.d/ssh start SSH 服务的配置文件位于 /etc/ssh/sshd_config。这个文件定义了 SSH 服务的各种参数,例如服务端口、身份验证方式等。默认情况下,SSH 服务的端口号是 22,可以在配置文件中修改为其他...

    Ubuntu 16.04远程登录服务器ssh的安装和配置.pdf

    在 /etc/ssh/sshd_config 文件中,需要修改 Authentication 部分,注释掉“PermitRootLogin without-password”并添加“PermitRootLogin yes”: sudo vi /etc/ssh/sshd_config Authentication #PermitRootLogin ...

    centos7 ssh8.6 rpm安装包

    SSH(Secure Shell)和SSL(Secure Sockets Layer)是两个至关重要的安全协议,用于远程管理和数据传输。本文将详细介绍如何在CentOS 7上安装SSH 8.6和OpenSSL 1.1.1k版本,以及相关的RPM(Red Hat Package Manager...

    Ubuntu SSH 安装教程.docx

    如果只有 ssh-agent,那么 ssh-server 还没有启动,需要使用 /etc/init.d/ssh start 命令启动。 八、使用 SSH 客户端登录 Ubuntu 使用 SSH 客户端登录 Ubuntu 需要输入服务器的 IP 地址和用户名密码,如果一切正常...

    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离线安装包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

    Ubuntu 20.04.1安装ssh离线资源包

    如果服务未启动,可以使用`sudo systemctl start ssh`手动启动,或者设置为开机自启动:`sudo systemctl enable ssh`。 配置SSH服务通常涉及修改`/etc/ssh/sshd_config`文件,例如设置端口、限制登录方式(如禁止...

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

    标题 "sudo for AIX5.3 在AIX6.1安装测试通过" 暗示了这个压缩包文件是 `sudo` 命令的一个版本,适用于AIX 5.3操作系统,并且已经在AIX 6.1系统上进行了安装和测试。`sudo` 是一个在Unix和Linux系统中广泛使用的命令...

    SSH配置示例

    `ssh-agent`启动代理,`ssh-add`添加私钥。 7. **增强安全性** 为了提高安全性,可以定期更换SSH密钥,限制失败尝试次数,使用更强的算法,或者配置密钥认证代理(Keychain)。 8. **SSH配置文件** 个人级别的...

    Ubuntu SSH 安装教程.pdf

    如果只有 ssh-agent,那 SSH 服务器还没有启动,需要: /etc/init.d/ssh start 如果看到 sshd,那说明 SSH 服务器已经启动了。 七、常见问题 1. SSH 客户端访问 Ubuntu SSH 服务器时出现中文乱码问题。 解决方法...

    ubuntu ssh服务器安装,ssh连接错误

    sudo systemctl status ssh ``` 如果SSH服务未启动,可以使用以下命令手动启动: ```bash sudo systemctl start ssh ``` 为了确保SSH服务在每次系统启动时自动运行,执行: ```bash sudo systemctl enable ssh `...

    ssh for hadoop

    对于基于Debian的系统,如Ubuntu,可以通过运行`sudo apt-get install ssh`来安装OpenSSH服务。而基于Red Hat的系统,如CentOS或RHEL,则可能需要使用`yum`或`dnf`包管理器。 #### 无密码SSH登录 为了提高效率,...

Global site tag (gtag.js) - Google Analytics