免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5597 | 回复: 7
打印 上一主题 下一主题

[网络相关] scp中,不同账户的key追加到主机的authorized_keys,为什么还需要密码? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2017-01-23 16:55 |只看该作者 |倒序浏览
为了使用scp不用密码,并且不同账户可以公用一个authorized_keys

账号A生成了id_rsa.pub_A
账号B生成了id_rsa.pub_B
把这两个都拷贝到主机上

到主机上执行:
cat id_rsa.pub_A >> authorized_keys
cat id_rsa.pub_B >> authorized_keys

可以为什么账户A或账户B用scp传文件到主机还是要密码呀?
但如果把authorized_keys换成单独的某个账户,就不需要密码,说明生成的KEY是没问题
就是公用的时候不行。。。。


论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2017-01-24 09:57 |只看该作者
账号得一样吧。
不能是不同账号。

论坛徽章:
0
3 [报告]
发表于 2017-01-24 10:06 |只看该作者
回复 2# flw

你的意思是说这种方法只能是不同机器,不能是不同的账号?

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2017-01-24 12:14 |只看该作者
是的。

论坛徽章:
24
申猴
日期:2014-10-10 15:56:39射手座
日期:2014-10-10 15:57:18黑曼巴
日期:2018-05-14 11:05:122016科比退役纪念章
日期:2018-05-14 11:05:0715-16赛季CBA联赛之北控
日期:2018-05-14 11:05:0015-16赛季CBA联赛之江苏
日期:2017-02-27 18:11:0715-16赛季CBA联赛之上海
日期:2018-08-15 09:48:5415-16赛季CBA联赛之佛山
日期:2018-07-20 17:14:2315-16赛季CBA联赛之佛山
日期:2019-09-10 18:08:4615-16赛季CBA联赛之山西
日期:2020-03-26 09:40:5115-16赛季CBA联赛之佛山
日期:2020-05-08 09:03:54
5 [报告]
发表于 2017-01-24 15:08 |只看该作者
本帖最后由 chengchow 于 2017-01-24 15:13 编辑

scp默认私钥读取的是id_isa文件,如果你生成时采用手动指定私钥和公钥,登录时需要用scp -i identified_files 登录
例如:秘钥对
私钥:aaa@abc.com
公钥:aaa@abc.com.pub

目标机器上user123用户下:cat aaa@abc.com.pub >> /home/user123/.ssh/authorized_keys

登录:scp -i aaa@abc.com  /tmp/aa.log user123@ip:/tmp


另外秘钥权限需要设置成600

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
6 [报告]
发表于 2017-01-24 20:43 |只看该作者
回复 1# wangzhixing_tt

账号A 生成了/home/A/.ssh/id_rsa.pub => HOST:/home/A/.ssh/authorized_keys

账号B生成了/home/B/.ssh/id_rsa.pub  => HOST:/home/B/.ssh/authorized_keys

论坛徽章:
18
辰龙
日期:2014-05-21 21:01:4115-16赛季CBA联赛之深圳
日期:2016-12-23 13:51:3815-16赛季CBA联赛之北控
日期:2016-11-28 18:26:3815-16赛季CBA联赛之佛山
日期:2016-11-03 11:18:5815-16赛季CBA联赛之辽宁
日期:2016-07-10 16:09:4115-16赛季CBA联赛之江苏
日期:2016-02-20 23:09:202015亚冠之塔什干棉农
日期:2015-08-17 19:49:492015年亚洲杯之日本
日期:2015-04-30 01:24:342015年亚洲杯之约旦
日期:2015-04-01 00:37:182015年亚洲杯之沙特阿拉伯
日期:2015-03-02 15:55:40处女座
日期:2014-05-25 10:34:0020周年集字徽章-年
日期:2023-04-23 11:17:52
7 [报告]
发表于 2017-01-25 14:30 |只看该作者
回复 1# wangzhixing_tt

直接用ssh-copy-id命令复制本地密钥到远程机器上去就行了。

NAME
     ssh-copy-id — use locally available keys to authorise logins on a remote machine
SYNOPSIS
     ssh-copy-id [-n] [-i [identity_file]] [-p port] [-o ssh_option] [user@]hostname
     ssh-copy-id -h | -?
DESCRIPTION
     ssh-copy-id is a script that uses ssh(1) to log into a remote machine (presumably using a login password, so password authentication should be
     enabled, unless you've done some clever use of multiple identities).  It assembles a list of one or more fingerprints (as described below) and
     tries to log in with each key, to see if any of them are already installed (of course, if you are not using ssh-agent(1) this may result in you
     being repeatedly prompted for pass-phrases).  It then assembles a list of those that failed to log in, and using ssh, enables logins with those
     keys on the remote server.  By default it adds the keys by appending them to the remote user's ~/.ssh/authorized_keys (creating the file, and
     directory, if necessary).  It is also capable of detecting if the remote system is a NetScreen, and using its ‘set ssh pka-dsa key ...’ command
     instead.


论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-09-07 06:20:00程序设计版块每日发帖之星
日期:2015-09-07 06:20:00
8 [报告]
发表于 2017-01-26 10:58 |只看该作者
我有三台机器,centos5,centos6,centos7,我让centos5和centos7的root用户免密码访问centos6的henry用户。
  1. [root@CentOS_5 .ssh]# scp id_rsa.pub 192.168.0.100:/home/henry
  2. id_rsa.pub                                                                                                             100%  398     0.4KB/s   00:00   
  3. [root@CentOS_5 .ssh]# pwd
  4. /root/.ssh
  5. [root@CentOS_6 henry]# mkdir .ssh; chmod 700 .ssh
  6. [root@CentOS_6 henry]# ll -d
  7. drwx------ 5 henry henry 4096 1月  26 10:52 .
  8. [root@CentOS_6 henry]# ll -d /home/henry/.ssh/
  9. drwx------ 2 root root 4096 1月  26 10:52 /home/henry/.ssh/
  10. [root@CentOS_6 henry]# cat id_rsa.pub >> .ssh/authorized_keys
  11. [root@CentOS_6 henry]# cd .ssh/
  12. [root@CentOS_6 .ssh]# ll
  13. 总用量 4
  14. -rw-r--r-- 1 root root 398 1月  26 10:53 authorized_keys
  15. [root@CentOS_6 .ssh]# id
  16. uid=0(root) gid=0(root) 组=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
  17. [root@CentOS_6 .ssh]# id henry
  18. uid=1001(henry) gid=1001(henry) 组=1001(henry)
  19. [root@CentOS_6 .ssh]# chown henry:henry authorized_keys
  20. [root@CentOS_6 .ssh]#
  21. [root@CentOS_6 .ssh]#
  22. [root@CentOS_6 .ssh]# ll -da
  23. drwx------ 2 root root 4096 1月  26 10:53 .
  24. [root@CentOS_6 .ssh]# cd ..
  25. [root@CentOS_6 henry]# ll -da
  26. drwx------ 5 henry henry 4096 1月  26 10:52 .
  27. [root@CentOS_6 henry]# ll -d
  28. drwx------ 5 henry henry 4096 1月  26 10:52 .
  29. [root@CentOS_6 henry]# ll -d .ssh/
  30. drwx------ 2 root root 4096 1月  26 10:53 .ssh/
  31. [root@CentOS_6 henry]# chown henry:henry .ssh/
  32. [root@CentOS_5 ~]# ssh henry@192.168.0.100
  33. Last login: Thu Jan  5 22:42:46 2017 from centos_5.11
复制代码

  1. [root@centos_7 .ssh]# scp id_rsa.pub 192.168.0.100:/home/henry
  2. id_rsa.pub
  3. [root@CentOS_6 henry]# su - henry
  4. [henry@CentOS_6 ~]$ pwd
  5. /home/henry
  6. [henry@CentOS_6 ~]$ ls
  7. id_rsa.pub
  8. [henry@CentOS_6 ~]$ cat id_rsa.pub >> .ssh/authorized_keys
  9. [root@centos_7 .ssh]# ssh henry@192.168.0.100
  10. Last login: Thu Jan 26 10:56:24 2017 from centos_5.11
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP