精美合同网站建设,网站建设可以自己弄吗知乎,建站快车凡科,wordpress企业模板中文0.说明平常使用ssh登陆远程服务器时#xff0c;都需要使用输入密码#xff0c;希望可以实现通过密钥登陆而免除输入密码#xff0c;从而可以为以后实现批量自动部署主机做好准备。环境如下#xff1a;IP地址操作系统服务器端10.0.0.128/24CentOS 6.5 x86客户端10.0.0.129/2… 0.说明 平常使用ssh登陆远程服务器时都需要使用输入密码希望可以实现通过密钥登陆而免除输入密码从而可以为以后实现批量自动部署主机做好准备。 环境如下IP地址操作系统服务器端10.0.0.128/24CentOS 6.5 x86客户端10.0.0.129/24Ubuntu 16.04 x861.客户端生成密钥对 生成密钥对xpleafleaf:~$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/xpleaf/.ssh/id_rsa):
Created directory /home/xpleaf/.ssh.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/xpleaf/.ssh/id_rsa.
Your public key has been saved in /home/xpleaf/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:eLssyXJLzUCfSN5mu6nqNH9dB/gOyXSvWBwQdNssIYE xpleafleaf
The keys randomart p_w_picpath is:
---[RSA 2048]----
| ooo |
| E .o |
| o oo o |
| .o . |
| So |
| B o o |
| o.... * o |
| ....o o |
| .o |
----[SHA256]----- 查看生成的密钥对xpleafleaf:~$ ls .ssh
id_rsa id_rsa.pub# id_rsa为私钥这个一般需要保密id_rsa.pub为公钥这个可以公开。2.上传公钥到服务器端 使用scp命令操作xpleafleaf:~$ scp .ssh/id_rsa.pub root10.0.0.128:/root
The authenticity of host 10.0.0.128 (10.0.0.128) cant be established.
RSA key fingerprint is SHA256:0Tpm11wruaQXyvOfEB1maIkEwxmjT2AklWb198Vrln0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 10.0.0.128 (RSA) to the list of known hosts.
root10.0.0.128s password:
id_rsa.pub 100% 393 0.4KB/s 00:00 3.服务器端操作 把从客户端传来的公钥添加到.ssh/authorized_keys中[rootleaf ~]# cat id_rsa.pub .ssh/authorized_keys
[rootleaf ~]# chmod 600 .ssh/authorized_keys# authorized_keys的权限需要为600 修改ssh配置文件/etc/ssh/sshd_config找到下面一行PubkeyAuthentication no 修改为PubkeyAuthentication yes4.测试 在客户端上使用密钥登陆到服务器上xpleafleaf:~$ ssh -i .ssh/id_rsa root10.0.0.128
Last login: Tue May 9 15:14:01 2017 from 10.0.0.129
[rootleaf ~]#5.注意事项在服务器端需要把selinux关闭否则最后无法使用密钥进行远程登陆客户端使用scp命令时在服务器端也需要安装ssh客户端否则无法把公钥上传到服务器端另外也可以使用ssh-copy-id root10.0.0.128来代替scp操作这样在服务器端也不需要执行创建.ssh目录等这些操作即相当于该命令可以一步帮我们完成密钥的上传与配置工作 转载于:https://blog.51cto.com/xpleaf/1924771