linux配置ssh某用户只允许证书登陆

1,客户端

生成公钥与私钥

ssh-keygen -t rsa -C ‘email’ -f ~/.ssh/user_ssh

然后会在~/.ssh生成user_ssh, user_ssh.pub

2,服务端

user登录服务端,并上传user_ssh.pub到服务端

配置ssh

touch ~/.ssh/authorized_keys 

cat user_ssh.pub >> ~/.ssh/authorized_keys 

sudo /etc/init.d/ssh start
 

禁止root账户并禁止所有用户密码登录

# Subsystem sftp /usr/lib/openssh/sftp-server  #关闭sftp

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PAM authentication via ChallengeResponseAuthentication may bypass
# If you just want the PAM account and session checks to run without
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
UseDNS no
AddressFamily inet
PermitRootLogin no  #禁止root
SyslogFacility AUTHPRIV
PasswordAuthentication no #禁止密码方式验证

 

 

3, 客户端测试  

使用xshell, 指定服务器信息之后,在验证设置中选择使用验证方法为public key

输入用户名, 选择我们在客户端生成的密钥, 如果生成公钥与私钥时候有输入通行密码即passphrase这里也要输入

然后就以”免密码“ 方式可以登录了。

我们再使用用户名密码ssh user@host这种方法登录则会如下图提示。

  

 

:D

以上个人简单笔记

转载于:https://www.cnblogs.com/shiv/p/5228102.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值