#返回当前用户cd#生成密钥
ssh-keygen -t rsa
#---------------------------------------------------------------
Generating public/private rsa key pair.
Enter fileinwhich to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:8Ar9Nslis+Iy9lL0VY9R7YNOIprTFZasXj5yooEpl5g root@single01
The key's randomart image is:
+---[RSA 2048]----+
|. o..|| B .||. + = o ||.. o+ = + o || +.=.*S= + .|| E *.*+=.+ .|| + =+*+ .||=...=.||. *o..|
+----[SHA256]-----+
#------------------------------------------------------------------
2.查看密钥
#列出文件ls -la
#--------------------------------------------------------
total 24
dr-xr-x---. 4 root root 138 Dec 2014:14 .
dr-xr-xr-x. 17 root root 224 Dec 20 09:13 ..
-rw-------. 1 root root 1403 Dec 20 09:14 anaconda-ks.cfg
-rw-r--r--. 1 root root 18 Dec 292013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 292013 .bash_profile
-rw-r--r--. 1 root root 176 Dec 292013 .bashrc
-rw-r--r--. 1 root root 100 Dec 292013 .cshrc
drwxr-----. 3 root root 19 Dec 2012:05 .pki
drwx------. 2 root root 38 Dec 2014:14 .ssh
-rw-r--r--. 1 root root 129 Dec 292013 .tcshrc
#---------------------------------------------------------ls .ssh/
#-----------------
id_rsa id_rsa.pub
#-----------------
3.本机免密
cat ./ssh/id_rsa.pub >> .ssh/authorized_keys
4.查看是否免密成功
ls .ssh
#----------------------------------
authorized_keys id_rsa id_rsa.pub
#----------------------------------
5.连接主机
ssh root@single01
#----------------------------------------------------------------------------------------
The authenticity of host'single01 (192.168.50.102)' can't be established.
ECDSA key fingerprint is SHA256:bInNUWaomyIdiZEbrXk00HZsCEQrgBTP0+RfD5RyQ/g.
ECDSA key fingerprint is MD5:9f:95:6c:5b:38:1f:a7:14:80:a6:96:21:19:cb:3e:37.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'single01,192.168.50.102' (ECDSA) to the list of known hosts
ssh root@single01
root@single01's password:
Last login: Mon Dec 2010:41:44 2021 from 192.168.50.1
#----------------------------------------------------------------------------------------