本文主要是介绍ssh, scp 不输入密码进行操作的方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
经常在不同linux机器之间互相scp拷文件,每次总是要输入密码才可行。 通过ssh-keygen生成公钥,在两台机器之间互相建立信任通道即可。 假设本地机器client,远程机器为server。 1. 生成rsa keygen [winter@client winter] $ ssh-keygen -b 1024 -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/winter/.ssh/id_rsa): <Enter> Enter passphrase (empty for no passphrase): <Enter> Enter same passphrase again: <Enter> Your identification has been saved in /home/winter/.ssh/id_rsa. Your public key has been saved in /home/winter/.ssh/id_rsa.pub. The key fingerprint is: 33:d4:7b:9c:87:04:cf:14:40:22:6d:c7:15:78:97:6a winter@client 直接上面公钥和私钥存放地址可以直接回车,私钥密码可以直接回车,也可以输入。 2. 查看.ssh目录下了多私钥和公钥文件 [winter@client winter] $ ls .ssh/ id_rsa id_rsa.pub known_hosts 3. 拷贝公钥到目标机器上,并改名成authorized_keys [winter@client winter] $ scp .ssh/id_rsa.pub winter@192.168.0.110:/home/winter/.ssh/authorized_keys The authenticity of host '192.168.0.110(192.168.0.110)' can't be established. RSA key fingerprint is 5b:78:e8:e9:dc:d8:db:bd:f7:66:44:e6:3b:ce:f2:79. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.0.110' (RSA) to the list of known hosts. winter@192.168.0.110's password: <Enter> id_rsa.pub 100% 221 1.2MB/s 00:00 首次scp命令时候还是会提示输入密码,还有是否继续链接的提示,以后 4. 测试ssh进入 [winter@client winter] $ ssh 192.168.0.110 5. ok,搞定! [winter@server winter] # it's ok!
这篇关于ssh, scp 不输入密码进行操作的方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!