转载注明来源: 本文链接 来自osnosn的博客,写于 2022-11-06.
基于 openSSH-8.0p1 , 测试成功。
创建 用于签发用户证书的密钥(用户CA)。管理员创建,私钥不传递。
ssh-keygen -t ed25519 -C user_ca@myCA -f user_ca。
得到两个文件,user_ca , user_ca.pub。
只是密钥对,不是证书。因为没做自签名证书。
让sshd服务端信任"用户CA"的公钥。(方法一,用户级)
建议限制 principals。如果多个服务器信任同一个CA,只要每个服务器上的 principals 都不同。
就能做到,用同一个CA签发的用户证书,能登录其中一个服务器,而不能登录别的服务器。
在sshd服务器上,用户的 ~/.ssh/authorized_keys 中加入一行(用户CA的公钥)。此文件权限mode要求是0600。
cert-authority,principals="host02,allhost" ssh-ed25519 AAAAC.....xx user_ca@myCA
内容为 user_ca.pub 文件的内容。
如果用户证书包含 host02 或 allhost 才能登录(此种情况不判断用户名)。
每个想用证书登录的用户的 ~/.ssh/authorized_keys 都要加一行。
~/.ssh/authorized_keys 中加入一行(用户CA的公钥)。cert-authority ssh-ed25519 AAAAC.....xx user_ca@myCA让sshd服务端信任"用户CA"的公钥。(方法二,全局系统级)
在sshd服务器上,在 /etc/ssh/sshd_config 中加入一行:
TrustedUserCAKeys /etc/ssh/user_ca_list.pub ,
重启 sshd 服务生效, service sshd restart。
这种配置,用户证书必须有principals,且包含用户名才能登录。
user_ca_list.pub 可以多行,CA公钥文件user_ca.pub的内容占其中一行。文件权限mode可以是0600或0644。
例如: ssh-ed25519 AAAAC.....xx Comment
静态限制 principals
在sshd服务器上,创建 principals 目录 mkdir /etc/ssh/principals。此目录权限mode要求是0755。
然后在 /etc/ssh/sshd_config 中再加入一行,重启 sshd 服务。
AuthorizedPrincipalsFile /etc/ssh/principals/%u 。
之后再次修改 user_ca_list.pub 和 /etc/ssh/principals/ 中的文件,无需重启sshd即生效。
AuthorizedPrincipalsFile,只能配置一个路径,不支持多个路径。/etc/ssh/principals/root 文件:## 注释:/etc/ssh/principals/root文件内容
principl_01
principl_02
动态限制 principals
在sshd服务器上, /etc/ssh/sshd_config 中再加入两行:
AuthorizedPrincipalsCommand /etc/ssh/princ.sh %u %U %s %i ,
AuthorizedPrincipalsCommandUser root , (或指定一个别的用户身份)
重启 sshd 服务生效, service sshd restart。
#!/bin/sh
# 例子 /etc/ssh/princ.sh 文件, 权限mode是 0755,owner,group 都是 root
# 传入四个参数 $1=username,$2=user ID, $3=证书的serial num, $4=证书的key ID
# 例子中, $3 $4 没有使用
# 因 OpenSSH 权限提升漏洞 (CVE-2021-41617), 此程序只能由管理员编写,不应该开放给用户修改。
host=myhost02
buf="$host-$1"
buf2=$(echo "$buf" |/bin/shasum -)
buf2=${buf2%% *-}
echo "$buf2"
if [ "$2" -eq 0 ]; then
echo "$host-root"
echo "allhost-root"
else
echo "$buf"
echo "allhost-user"
fi
AuthorizedPrincipalsCommandUser abc 指定程序以 abc 用户身份执行。
可以接受 "%u" 表示以登录的身份执行, 但不建议。
另一个例子,也可以通过webserver查询principals。
AuthorizedPrincipalsCommand /bin/curl -s http://localhost/sshprincipals?user=%u&serial=%s&id=%i
任何用户登录,使用的用户证书,签名的CA在TrustedUserCAKeys列表中,
sshd 都会先检查 AuthorizedPrincipalsFile 中的 principals,
如果找不到,才会执行 AuthorizedPrincipalsCommand 程序。
如果程序的输出中,也没有找到匹配的 principals,则认证失败。
任何用户登录,使用的用户证书,签名的CA不在TrustedUserCAKeys列表中,
sshd不使用AuthorizedPrincipalsFile,AuthorizedPrincipalsCommand中的principals。
用户证书的签名CA通过TrustedUserCAKeys认证的,都必须有principals。
无principals的用户证书,不能登录。即使sshd服务端的principals为空,也不能登录。
有AuthorizedPrincipalsFile或AuthorizedPrincipalsCommand配置时,
这种情况不匹配用户名,用户证书的principals包含"用户名"无用。
只要是用这个密钥(用户CA)签名过的用户公钥,满足 principals 要求,就能登录此sshd服务器的相应用户。
创建用户密钥。用户自己创建,私钥不传递。
ssh-keygen -t ed25519 -C user@myhost -f users_key
得到两个文件,users_key , users_key.pub。
用 user_ca (私钥)对用户密钥的公钥签名,得到一个用户证书。
只把用户公钥发给管理员签名即可。只须要有"users_key.pub"公钥文件,无需用户的私钥文件。
ssh-keygen -s user_ca -I ident -z 01 -n user1,principal_02 -V -10m:+90d users_key.pub
得到一个文件 users_key-cert.pub,发回给用户。
-n user1,principal_02 限制证书的用户名 或principals。不限制就去掉这个参数。
-V -1m:+10d 限制证书的时效。不限制就去掉这个参数。
-O source-address=192.168.123.0/24,10.1.2.3 限制来源IP。
-O force-command="date" 强制只执行某个命令。
-z 01 序号,数字。
查看已经签名的用户证书的内容。
ssh-keygen -L -f users_key-cert.pub。
在ssh客户端上,
把两个文件放在一起 users_key , users_key-cert.pub。这个文件没用 users_key.pub。
用命令 ssh user1@sshd服务器 -i users_key 就能够登录了。
创建或更新 KRL 文件。然后把 KRL 文件传到sshd服务器上。或者直接在sshd服务器上创建或更新。
创建 revoke 文件,并把证书加入: ssh-keygen -k -z 01 -f KRL_file key-cert.pub。
更新 revoke 文件,并把公钥加入: ssh-keygen -ku -z 01 -f KRL_file key.pub。
更新 revoke 文件,并把CA公钥加入: ssh-keygen -ku -z 01 -f KRL_file user_ca.pub。
其中 -z 01 序号,数字。在 KRL 中作为版本号。
不仅能吊销ca签名证书,也可以吊销普通密钥的公钥。
列出 KRL 文件内容: ssh-keygen -Ql -f KRL_file。
测试 key-cert.pub 是否被 revoked : ssh-keygen -Q -f KRL_file key-cert.pub。
KRL 文件也可以是纯文本的,不用 ssh-keygen 生成,格式同/etc/ssh/user_ca_list.pub,一行一个公钥。
例如: ssh-ed25519 AAAAC.....xx Comment
可以是CA公钥 user_ca.pub,也可以是普通密钥的公钥,也可以是用户证书users_key-cert.pub的内容。
让sshd服务器检查 KRL 文件。(KRL文件,纯文本或者二进制格式,都支持)
在sshd服务器上, /etc/ssh/sshd_config 中加入一行 RevokedKeys /path_to/KRL_file ,
重启 sshd 服务生效, service sshd restart。
/path_to/KRL_file 文件的权限mode可以是 0600 或 0644。
之后再次修改 KRL 文件,无需重启sshd。
sshd服务器会最先检查 KRL 文件。
即,会吊销在 TrustedUserCAKeys,AuthorizedKeysFile,AuthorizedKeysCommand中的公钥。
区别:
/etc/ssh/sshd_config 中加入两行:AuthorizedKeysCommandUser /etc/ssh/keys.sh %u %UAuthorizedKeysCommandUser root , (或指定一个别的用户身份)service sshd restart。#!/bin/sh
# 例子 /etc/ssh/keys.sh 文件, 权限mode是 0755,owner,group 都是 root
# 传入两个参数 $1=username,$2=user ID
# 例子中, $1 $2 没有使用
# 因 OpenSSH 权限提升漏洞 (CVE-2021-41617), 此程序只能由管理员编写,不应该开放给用户修改。
echo "ssh-ed25519 AAAAC.....xx Comment" # 普通密钥的公钥
echo "cert-authority ssh-ed25519 AAAAC.....xx Comment" # CA的公钥,无principals限制
# CA的公钥, 有principals限制
echo 'cert-authority,principals="host02,allhost" ssh-ed25519 AAAAC.....xx Comment'
AuthorizedKeysCommandUser abc 指定程序以 abc 用户身份执行。AuthorizedKeysFile 中的公钥,AuthorizedKeysCommand 程序。TrustedUserCAKeys。AuthorizedKeysFile或AuthorizedKeysCommand中找到,principals="" 。AuthorizedPrincipalsFile,AuthorizedPrincipalsCommand的cert-authority...匹配行中,
principals= 则用户证书无principals可以登录,或者用户证书有principals,且包含用户名 才能登录。principals="xx02,xx03" 则用户证书有principals,且包含任意一个principal 才能登录。ssh-keygen -t ed25519 -C server_ca@myCA -f server_ca。server_ca , server_ca.pub。~/.ssh/known_hosts 中加入一行(服务器CA的公钥)。此文件权限mode通常是0644。@cert-authority * ssh-ed25519 AAAAC.....xx server_ca@myCA/etc/ssh/ssh_known_hosts 中加入一行(服务器CA的公钥)。此文件权限mode是0644。@cert-authority * ssh-ed25519 AAAAC.....xx server_ca@myCAssh_host_ecdsa_key.pub,ssh_host_ed25519_key.pub,ssh_host_rsa_key.pub。ssh-keygen -s server_ca -I ident -z 01 -h /etc/ssh/ssh_host_ed25519_key.pubssh_host_ed25519_key-cert.pub。-h 参数,漏了就无效了。-V -1m:forever -n "*.myhost.cn,*.xxx.com"-n abc.mydomain.com 限制证书的域名,IP。不限制就去掉这个参数。-V -1m:+3d 限制证书的时效。不限制就去掉这个参数。-z 01 序号,数字。ssh-keygen -L -f ssh_host_ed25519_key-cert.pub。/etc/ssh/sshd_config 加三行,HostCertificate /etc/ssh/ssh_host_ecdsa_key-cert.pubHostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pubHostCertificate /etc/ssh/ssh_host_rsa_key-cert.pubHostCertificate /etc/ssh/.... 就只写一行吧。/sbin/service sshd reload。ssh user1@sshd服务器 就没有连接警告了。~/.ssh/known_hosts 中加入一行的公钥。@revoked * ssh-ed25519 AAAAC.....xx server_ca@myCAssh_host_ed25519_key-cert.pub的内容。/etc/ssh/ssh_config 中加入 RevokedHostKeys /path_to/KRL_file,/path_to/KRL_file文件权限mode是0644。ssh-keygen生成的二进制格式。/etc/ssh/ssh_known_hosts 中加入一行,也可以。此文件权限mode是0644。@revoked * ssh-ed25519 AAAAC.....xx server_ca@myCAcd /etc/ssh/
ssh-keygen -l -f ssh_host_rsa_key #看一下,原来密钥的注释是什么。然后决定下面的 -C 参数写什么
ssh-keygen -t ecdsa -b 384 -C root@你的机器名 -f ssh_host_ecdsa_key
ssh-keygen -t ed25519 -C root@你的机器名 -f ssh_host_ed25519_key
ssh-keygen -t rsa -b 4096 -C root@你的机器名 -f ssh_host_rsa_key
service sshd restart #重启sshd服务
rm /etc/ssh/ssh_host_* , 重新用默认值生成一遍 ssh-keygen -A。service sshd restart。---end---
转载注明来源: 本文链接 https://www.cnblogs.com/osnosn/p/16870594.html 来自osnosn的博客.
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po