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

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐