关于服务器之间的无密码登录自己的实践

整体思路是在开始时安装网上的方式生成秘钥,然后将公钥发送到对应的服务器上,成功了就可以实现了
自己遇到的坑

第一次尝试:
由于从网上拷贝的这个命令ssh-cory-id失效,认为ssh-cory-id这个命令不可用
就用了如下方法:

cat ~/.ssh/id_*.pub | ssh  root@101.200.57.125 'cat >> .ssh/authorized_keys'
ssh-cory-id -i ~/.ssh/id_rsa.pub root@101.200.57.125
手打的可以,拷贝的不行

cat ~/.ssh/id_*.pub | ssh  root@101.200.57.125 'cat >> .ssh/authorized_keys'


这个方式有个弊端就是需要自己去写入ssh root@101.200.57.125 ,而不是ssh 101.200.57.125,有点不完美

第二次尝试:
自己重新
按照这个网址

[root@hadoop100 admin]# ssh-cory-id -i ~/.ssh/id_rsa.pub root@101.200.57.125
bash: ssh-cory-id: command not found...
[root@hadoop100 admin]# yum -y install openssh-clients
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.tuna.tsinghua.edu.cn
Package openssh-clients-7.4p1-21.el7.x86_64 already installed and latest version
Nothing to do
[root@hadoop100 admin]# ssh-cory-id -i ~/.ssh/id_rsa.pub root@101.200.57.125
bash: ssh-cory-id: command not found...
[root@hadoop100 admin]# curl -L https://raw.githubusercontent.com/beautifulcode/ssh-copy-id-for-OSX/master/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed connect to raw.githubusercontent.com:443; Connection refused
[root@hadoop100 admin]# yum -y uninstall openssh-clients
Loaded plugins: fastestmirror, langpacks
No such command: uninstall. Please use /usr/bin/yum --help
[root@hadoop100 admin]# yum -y install openssh-clients
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.tuna.tsinghua.edu.cn
Package openssh-clients-7.4p1-21.el7.x86_64 already installed and latest version
Nothing to do
[root@hadoop100 admin]# service sshd start
Redirecting to /bin/systemctl start sshd.service
[root@hadoop100 admin]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service
[root@hadoop100 admin]# ssh-cory-id 
bash: ssh-cory-id: command not found...
[root@hadoop100 admin]# sudo yum install sshd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.tuna.tsinghua.edu.cn
No package sshd available.
Error: Nothing to do
[root@hadoop100 admin]# service sshd stop
Redirecting to /bin/systemctl stop sshd.service
[root@hadoop100 admin]# service sshd start
Redirecting to /bin/systemctl start sshd.service
[root@hadoop100 admin]# service sshd status
Redirecting to /bin/systemctl status sshd.service
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-09-30 15:20:38 CST; 17s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 8170 (sshd)
    Tasks: 1
   CGroup: /system.slice/sshd.service
           └─8170 /usr/sbin/sshd -D

Sep 30 15:20:38 hadoop100 systemd[1]: Starting OpenSSH server daemon...
Sep 30 15:20:38 hadoop100 sshd[8170]: Server listening on 0.0.0.0 port 22.
Sep 30 15:20:38 hadoop100 sshd[8170]: Server listening on :: port 22.
Sep 30 15:20:38 hadoop100 systemd[1]: Started OpenSSH server daemon.
[root@hadoop100 admin]# ll
total 0
drwxr-xr-x. 2 admin admin 6 Aug 30 01:08 Desktop
drwxr-xr-x. 2 admin admin 6 Aug 30 01:08 Documents
drwxr-xr-x. 2 admin admin 6 Aug 30 01:08 Downloads
drwxr-xr-x. 2 admin admin 6 Aug 30 01:08 Music
drwxr-xr-x. 2 admin admin 6 Aug 30 01:08 Pictures
drwxr-xr-x. 2 admin admin 6 Aug 30 01:08 Public
drwxr-xr-x. 2 admin admin 6 Aug 30 01:08 Templates
drwxr-xr-x. 2 admin admin 6 Aug 30 01:08 Videos
[root@hadoop100 admin]# ssh 125
ssh: connect to host 125 port 22: Invalid argument
[root@hadoop100 admin]# ssh
usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
           [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]
[root@hadoop100 admin]# ssh
ssh          ssh-add      ssh-agent    ssh-copy-id  sshd         sshd-keygen  ssh-keygen   ssh-keyscan  
[root@hadoop100 admin]# sshd
sshd re-exec requires execution with an absolute path
[root@hadoop100 admin]# ssh-copy-id
Usage: /usr/bin/ssh-copy-id [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
	-f: force mode -- copy keys without trying to check if they are already installed
	-n: dry run    -- no keys are actually copied
	-h|-?: print this help
[root@hadoop100 admin]# ssh-cory-id -i ~/.ssh/id_rsa.pub root@101.200.57.125
bash: ssh-cory-id: command not found...
[root@hadoop100 admin]# ssh-cory-id -i
bash: ssh-cory-id: command not found...
[root@hadoop100 admin]# ssh-cory-id 
bash: ssh-cory-id: command not found...
[root@hadoop100 admin]# sshd
sshd re-exec requires execution with an absolute path
[root@hadoop100 admin]# ssh-copy-id
Usage: /usr/bin/ssh-copy-id [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
	-f: force mode -- copy keys without trying to check if they are already installed
	-n: dry run    -- no keys are actually copied
	-h|-?: print this help
[root@hadoop100 admin]# ssh-copy-id -i
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
Usage: /usr/bin/ssh-copy-id [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
	-f: force mode -- copy keys without trying to check if they are already installed
	-n: dry run    -- no keys are actually copied
	-h|-?: print this help
[root@hadoop100 admin]# ssh-cory-id -i ~/.ssh/id_rsa.pub root@101.200.57.125
bash: ssh-cory-id: command not found...
[root@hadoop100 admin]# ssh-copy-id -i 
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
Usage: /usr/bin/ssh-copy-id [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
	-f: force mode -- copy keys without trying to check if they are already installed
	-n: dry run    -- no keys are actually copied
	-h|-?: print this help
[root@hadoop100 admin]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@101.200.57.125
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/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
root@101.200.57.125's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@101.200.57.125'"
and check to make sure that only the key(s) you wanted were added.

[root@hadoop100 admin]# ssh 101.200.57.125
Last login: Wed Sep 30 15:01:24 2020 from 121.69.104.54

Welcome to Alibaba Cloud Elastic Compute Service !

➜  ~ exit
Connection to 101.200.57.125 closed.
[root@hadoop100 admin]# ssh 125
ssh: connect to host 125 port 22: Invalid argument
[root@hadoop100 admin]# 

就是yum 按装的sshd 重启,还是不行,自己就手敲了一下发现命令可以执行所有就开心了。

第二个问题就是hostname的问题了,给ip取别名,直接连接

这个也是尝试了好多了,只改变/etc/hosts 配置还不行
需要加入
vim /etc/sysconfig/network
原来是这个,需要加一个配置文件即可
https://blog.csdn.net/xlgen157387/article/details/50282483
在这里插入图片描述
最大的坑是自己打错了,把copy 写成了 cory 真该打!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值