ubuntu 18.04.4 设置ssh密码免登陆
需求A主机免密登陆到B主机
1 在B主机以一个正确的方式创建用户,此步骤这是针对ubuntu
root@pengxiao: sudo useradd -r -m -s /bin/bash xiaopeng #创建一个用户名,这样的话会自动创建目录\
其中参数的意义如下:
-r:建立系统账号
-m:自动建立用户的登入目录
-s:指定用户登入后所使用的shell
root@pengxiao: passwd xiaopeng #设置密码
2 在A主机上面设置ssh
root@pengxiao: ssh-keygen #一直回车
root@pengxiao: cd /root/.ssh
root@pengxiao: sudo ssh-copy-id -p 9108 -i id_rsa.pub xiaopeng@10.10.66.2 #将id_rea.pub 拷贝到66.2,中间会被要求数据B主机xiaopeng密码
命令说明:
-i 是指定目录
ssh xiaopeng@10.10.66.2 -p 9108 # A主机直接ssh 到B主机可以发现不用密码了
root@pengxiao:~/.ssh# ssh xiaopeng@10.10.66.2 -p 9108
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-118-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage