已验证 ubuntu生成pem证书连接服务器( 二 )


文章插图
测试现在就可以用xj_xiaojin文件来连接了
$ ssh -i xjdemo_xiaojinxj@172.25.1.230

已验证 ubuntu生成pem证书连接服务器

文章插图
或者把 xj_xiaojin重命名为 xj_xiaojin.pem
$ ssh -i xj_xiaojin.pemxj@172.25.1.230更优化的做法,直接ssh就可以了,不需要密码
ssh xj@172.25.1.230禁用密码连接
注意:要保证 .pem 连接成功的状态下,禁用密码连接
$ sudo vi /etc/ssh/sshd_config找到这一行 #PasswordAuthentication yes
# Change to no to disable tunnelled clear text passwords# PasswordAuthentication yes取消前边的 # 注释,改为
PasswordAuthentication no重启 ssh服务
$ sudo service ssh restart好了,教程这到这里结束了
服务器方案新增用户root@xjTEST:~/.ssh# adduser kingAdding user `king' ...Adding new group `king' (1001) ...Adding new user `king' (1001) with group `king' ...Creating home directory `/home/king' ...Copying files from `/etc/skel' ...New password:Retype new password:passwd: password updated successfullyChanging the user information for kingEnter the new value, or press ENTER for the defaultFull Name []:Room Number []:Work Phone []:Home Phone []:Other []:Is the information correct? [Y/n] Yroot@xjTEST:~/.ssh#赋予root权限$ chmod 700 /etc/sudoers$ vi /etc/sudoers# User privilege specificationrootALL=(ALL:ALL) ALL下边增加kingALL=(ALL:ALL) ALL$ chmod 400 /etc/sudoers生成密钥对root@xjTEST:~/.ssh# cd /home/king/root@xjTEST:/home/king# mkdir .sshroot@xjTEST:/home/king# cd .ssh/root@xjTEST:/home/king/.ssh# ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): king_8.134.210.33.pemEnter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in king_8.134.210.33.pemYour public key has been saved in king_8.134.210.33.pem.pubThe key fingerprint is:SHA256:mAa0TRY+kECFCqU6nPfunpWeiRAStvIXnw3dqVz1iS8 root@xjTESTThe key's randomart image is:+---[RSA 3072]----+| o+++.+.||.....B||o+o +.||= +. = . o o . ||+= o. = S + . o||.oo o+ =.o.||....oo+E .||.o = o.||o* +|+----[SHA256]-----+root@xjTEST:/home/king/.ssh# lsking_8.134.210.33.pemking_8.134.210.33.pem.pub服务器认证证书root@xjTEST:/home/king/.ssh# cat king_8.134.210.33.pem.pub >> authorized_keys客户端登录把私钥传到客户端,放到~/.ssh目录中
xiaojin@xiaojin-PC:~/.ssh$ ssh -i ~/.ssh/king_8.134.210.33.pem king@8.134.210.33好了教程就到这里结束了 。

经验总结扩展阅读