Linux下实现获取远程机器文件

时间:2023-03-08 16:18:39

创建公钥秘钥实现无密码登录后即可获取到文件内容了!!

A:xxx.xxx.6.xxx

B:xxx.xxx.xxx.x

一、创建

A机器

ssh-keygen -t rsa

二、拷贝——将生成的公钥复制到B机器

scp /root/.ssh/id_rsa.pub root@xxx.xxx.xxx.x:/root/.ssh/authorized_keys

输入B机器的密码

三、授权

B机器

chmod 700 /root

chmod 700 /root/.ssh

chmod 600 /root/.ssh/authorized_keys

测试:

在A机获取B机上的文件

scp root@xxx.xxx.xxx.x:/usr/local/Inst/index.php /mnt/tomcat/

注意

此时如果要是A、B两机器访问无需密码,则只要将机器的顺序调换一下即可,最后将两台机器上/root/.ssh下的id_rsa.pub文件删除

查看实时登录信息

tail -f messages /var/log/secure

查看配置

vi /etc/ssh/sshd_config

查看登录信息

ssh -i authorized_keys -v root@xxx.xxx.xxx.x -p22

https://gopukrish.wordpress.com/2013/04/24/ssh-cant-connect-authentications-that-can-continue-publickeygssapi-keyexgssapi-with-micpassword/