版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yitengtongweishi/article/details/81946083
安装 ssh
blockchain@Dao:~$ sudo apt-get install openssh-server
配置 ssh 免密码登陆
blockchain@Dao:~$ ssh localhost
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is 70:a2:a9:3c:d3:b7:db:e3:eb:5a:e4:98:60:89:a2:ba.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
blockchain@localhost's password:
Permission denied, please try again.
blockchain@localhost's password:
Permission denied, please try again.
blockchain@localhost's password:
Permission denied (publickey,password).
blockchain@Dao:~$
此时,会要求输入密码,不用管,直接回车即可。进入刚生成的 .ssh 目录,
blockchain@Dao:~$ cd .ssh ; ls -lt
total 4
-rw-r--r-- 1 blockchain blockchain 222 8月 22 11:26 known_hosts
blockchain@Dao:~/.ssh$
生成密钥,不用管提示,一直按回车。
blockchain@Dao:~/.ssh$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/blockchain/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/blockchain/.ssh/id_rsa.
Your public key has been saved in /home/blockchain/.ssh/id_rsa.pub.
The key fingerprint is:
50:7b:6c:91:31:bd:9c:c3:07:50:ef:b2:53:2d:e5:d3 blockchain@Dao
The key's randomart image is:
+--[ RSA 2048]----+
| . =*. |
| . o.oo. |
| . . +o +. .|
| . o *..+.|
| S .o+.E|
| + ..|
| o |
| . |
| |
+-----------------+
blockchain@Dao:~/.ssh$ ls -lt
total 12
-rw------- 1 blockchain blockchain 1679 8月 22 11:32 id_rsa
-rw-r--r-- 1 blockchain blockchain 396 8月 22 11:32 id_rsa.pub
-rw-r--r-- 1 blockchain blockchain 222 8月 22 11:26 known_hosts
加入授权
blockchain@Dao:~/.ssh$ cat ./id_rsa.pub >> ./authorized_keys
blockchain@Dao:~/.ssh$ ls -lt
total 16
-rw-rw-r-- 1 blockchain blockchain 396 8月 22 11:33 authorized_keys
-rw------- 1 blockchain blockchain 1679 8月 22 11:32 id_rsa
-rw-r--r-- 1 blockchain blockchain 396 8月 22 11:32 id_rsa.pub
-rw-r--r-- 1 blockchain blockchain 222 8月 22 11:26 known_hosts
测试免密码登录
blockchain@Dao:~$ ssh localhost
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-133-generic x86_64)
* Documentation: https://help.ubuntu.com/
0 packages can be updated.
0 updates are security updates.
New release '16.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Wed Aug 22 16:15:39 2018 from localhost
blockchain@Dao:~$
blockchain@Dao:~$ exit
logout
Connection to localhost closed.
blockchain@Dao:~$
免密码登录成功。