# 2\. 使用使用ssh-copy-id将公钥添加到服务器
# 通过-i指定添加test.pub到服务器上指定用户的~/.ssh/authorized_keys文件中
# ssh-copy-id会提示输入密码以登陆服务器,并进行后续操作
#
[test@CentOS-7 ~]# ssh-copy-id -i test.pub test@127.0.0.1
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
test@127.0.0.1
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'test@127.0.0.1'"
and check to make sure that only the key(s) you wanted were added.
# 3\. 使用私钥登陆服务器
# 通过ssh -i指令选择要使用的私钥文件'test'
# 使用-v指令打印出ssh登陆服务器的处理流程,便于debug
#
[test@CentOS-7 ~]$ ssh -i test test@127.0.0.1 -v
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file test type 1
debug1: identity file test-cert type -1
...
debug1: Next authentication method: publickey
debug1: Offering RSA public key: test # NOTE
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey). # NOTE
Authenticated to 127.0.0.1 ([127.0.0.1]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Last login: Tue Jul 14 23:31:40 2015 from localhost
# 4\. 现在已经在服务器上了,查看.ssh/authorized_keys的内容吧
#
[test@CentOS-7 ~]# ll .ssh/
total 4
-rw-------. 1 test test 408 Jul 14 23:18 authorized_keys
[root@CentOS-7 test]# cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDegiE85/x22gJzjJIiex9dgpB37wWQDcC++E6N+RUpu1osKek10BybmSmD8U5N6F77kQc4PW1S5y9XwGG5oJBGmlZhJmcelRjiJVWWlZyOM806saxpuR4DEvx6cLCCimrorUnkkAZOVl3t/15fZr/7aT/MwryLWBOO0RmGOybDqnkLgoaPOAVk8vokdjXoDQW7uAXnRVwhKzyx5M0jiPeDfSYfkcaan+zsIPa8mmnwTYawcO36D9TtIKzM/ZzZAMi/ZsDL49uOC2GMYNfkzpwRJQUn3OqFih/njmG/HqRcrlFsemAwfSJ0wmAGf42sHdSrSx5CjUQCQ7mapscMpzaL test@localhost.localdomain