SSH 证书认证配置方法

1、默认安装完以后用VI打开 /etc/ssh/sshd_config 修改几行内容就可以了
#ServerKeyBits 768 注释取消,将768改为1024
#PermitRootLogin yes 注释取消,将yes改为no 禁止root登录
#PermitEmptyPasswords no 取消注释,禁止空密码登录
#PasswordAuthentication no 取消注释,禁止使用密码方式登录,有密钥谁还用密码啊
注意一下,在centos5.0之前SSH服务需要指明版本,#Protocol 2,1 把前面的注释取消,选择自己需要的版本就行了。
保存退出。如果想做到最大化安全链接,可以考虑在配置有双网卡的服务器上设置只允许内网链接SSH,方法很简单,在/etc/hosts.deny文件最后一行添加一句sshd: ALL 然后在/etc/hosts.allow的最后一行加上一句sshd: 192.168.0. 然后保存退出。
重启一下SSH服务 service sshd restart 就OK了


2、制作密钥
先切换进入一个wheel组的普通用户,输入 ssh-keygen -t rsa.
第一步会让你先确认钥匙的文件名。保持默认就可以了。然后输入这个密钥的口令,再确认一次就可以了。
然后cd ~/.ssh 查看一下钥匙是不是都已经建立了。将公钥更改名称后删除
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
rm -rf ~/.ssh/id_rsa.pub 别把密钥误删就行了。
将公钥文件属性更改为400禁止被篡改
chmod 400 ~/.ssh/authorized_keys
剩下的就没什么了,把密钥COPY到U盘还是FTP服务器再转移或者是复制到磁盘上就看你自己的需要了。
测试一下看服务能不能正常连接
打开puttygen-x86.exe 在程序下面选择SSH-2(RSA)密钥强度改为1024,然后点击"Load"
选取服务器端生成的私钥(文件类型要选择“All Files”)如果没有改名字的话我们选的应该是id_rsa这个文件,开始转换私钥,这里需要输入在服务器端建立此私钥时的口令。在文本框中输入口令开始转换,保存转换后的私钥匙到适当的位置(转换后的私钥将做为PuTTY登录到服务器时使用的私钥)。点击“Save private key”,并选择适当的位置保存私钥。
PUTTY 估计做网管的朋友都很熟悉,下载地址就不废话了,没有可以下载我附件里提供的,我感觉这样的兵器绝对是每人必备一把的,双击启动 PuTTY ,在左侧找到Auth(认证方式)一项,点击Browse,选择刚刚用PuTTYGen转换后的私钥。然后点击左侧的Session,回到主机连接信息的设置。剩下的我就不罗嗦了,自己试试就行了。
 
服务器间通讯
假设两台Linux服务器:server1和server2,我们以用户dboper为例(即两台服务器上均创建有dboper用户)。
在server1上,以dboper登录。执行如下命令:
ssh-keygen -d
Generating public/private dsa key pair.
Enter file in which to save the key (/home/wuysh/.ssh/id_dsa): (采用缺省值,回车)
Enter passphrase (empty for no passphrase): (不用密码了,回车)
Enter same passphrase again: (回车)
Your identification has been saved in /home/wuysh/.ssh/id_dsa.
Your public key has been saved in /home/wuysh/.ssh/id_dsa.pub.
The key fingerprint is:
b2:a4:92:12:7f:15:9b:89:48:2a:7c:3a:d6:17:ea:ab dboper@localhost.localdomain
这样,在用户的.ssh目录下生成如下两个文件:
id_dsa
id_dsa.pub
在用户的.ssh目录下,将id_dsa.pub复制一份成 authorized_keys1 文件, 并将 authorized_keys1 的属性改为 600 即文件所属用户有读和写的权限,组用户和其它用户禁止读写。
cp id_dsa.pub authorized_keys1
chmod 600 authorized_keys1
然后在server2上,也以dboper登录,也执行上面的一次操作。
这样,两台服务器上都生成了用户的公钥和私钥,接下来就是进行互相认证了。即把公钥放到对方服务器。
server2信认server1,即server1登录server2不用输入密码:
复制server1上的id_dsa.pub到server2(不要覆盖server2上的id_dsa.pub),复制成id_dsa.pub_server1。然后将id_dsa.pub_server1的内容添加到server2上的dboper用户.ssh目录下的authorized_keys文件中
cat id_dsa.pub_server1 >> authorized_keys
OK,现在你在server1上以dboper用户来登录server2,将不再需要密码了。
ssh dboper@server2
立即进入,没有密码输入提示了。
如果要在server1上信认server2,按上面的方法,把server2上的id_dsa.pub中的内容添加到server1上用户.ssh目录下的authorized_keys文件中。
Linux系统导入xshell中导入的是私钥
xshell导入Linux系统导入的是公钥
Linux系统间认证交换的是公钥


#	$OpenBSD: sshd_config,v 1.73 2005/12/06 22:38:28 reyk Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

#Port 22
#Protocol 2,1
Protocol 2
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 768

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6

#RSAAuthentication yes
#PubkeyAuthentication yes
AuthorizedKeysFile	.ssh/authorized_keys

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes

# 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 mechanism. 
# Depending on your PAM configuration, this may bypass the setting of 
# PasswordAuthentication, PermitEmptyPasswords, and 
# "PermitRootLogin without-password". If you just want the PAM account and 
# session checks to run without PAM authentication, then enable this but set 
# ChallengeResponseAuthentication=no
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES 
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT 
AcceptEnv LC_IDENTIFICATION LC_ALL
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner /some/path

# override default of no subsystems
Subsystem	sftp	/usr/libexec/openssh/sftp-server


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在2021年,使用Ubuntu搭建SSH证书登录是一种安全可靠的方法SSH证书是用于验证用户身份的一种方式,相比于传统的用户名和密码认证方式更加安全。 在Ubuntu上生成SSH证书的步骤通常如下: 1. 在终端中运行ssh-keygen命令来生成公钥和私钥,可以指定算法、密钥长度等参数。 2. 设置密码以保护私钥的安全。 3. 在~/.ssh目录下生成的id_rsa.pub文件中找到公钥,将其复制。 4. 在目标服务器上创建一个新用户,例如使用adduser命令。 5. 将复制的公钥粘贴到目标服务器新用户的~/.ssh/authorized_keys文件中。 6. 修改目标服务器上SSH配置文件/etc/ssh/sshd_config,确保PubkeyAuthentication设置为yes。 7. 重启SSH服务以使修改生效。 使用证书登录后,你可以删除或禁用传统的用户名和密码登录方式,提高系统的安全性。此外,使用证书登录在多台服务器之间切换时也更加方便,无需每次输入密码。 在Ubuntu中管理SSH证书也比较简单。你可以使用ssh-add命令将私钥添加到SSH agent中,这样可以在登录时自动使用证书进行身份验证。如果需要撤销或更改证书,可以使用ssh-keygen命令重新生成新的密钥对,并更新目标服务器的authorized_keys文件。 总之,Ubuntu上使用SSH证书登录是一种安全、高效的身份验证方式,可以增加系统的安全性和便利性。在2021年以及将来的时间里,它仍然是一种被广泛使用的方法。 ### 回答2: Ubuntu系统中,SSH证书是用于身份验证和安全连接的一种机制。2021年的Ubuntu系统中使用SSH证书仍然是一种常见且安全的方法SSH证书通常由公钥和私钥组成。公钥部分存储在目标服务器的".ssh/authorized_keys"文件中,而私钥则保存在客户端的".ssh"文件夹中。在使用SSH登录远程服务器时,客户端会使用私钥进行加密,服务器使用公钥进行解密和验证身份。 使用SSH证书的好处是它允许用户在无需输入密码的情况下进行远程登录,提供了更高的安全性。同时,SSH证书还可以防止中间人攻击,因为私钥只存在于客户端,不会在网络中传输。 生成SSH证书方法很简单。首先,在目标服务器上创建一个新的密钥对,使用命令"ssh-keygen"生成公钥和私钥。然后将公钥复制到服务器的"authorized_keys"文件中。最后,将私钥复制到客户端的".ssh"文件夹中,确保私钥的权限设置正确。 使用SSH证书进行远程连接时,只需提供私钥的路径和用户名即可,无需输入密码。这样可以方便、安全地进行远程操作。 总的来说,Ubuntu系统中的SSH证书仍然是一种可靠且广泛应用的身份验证机制。通过生成公钥和私钥,并在服务器和客户端进行相应配置,可以实现安全、免输入密码的远程连接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值