是否有可用于Windows的任何等效或端口ssh-copy-id? 也就是说,有没有一种简单的方法将SSH密钥从本地机器传输到Windows下的远程服务器?
如果它有帮助,我已经使用了选美和凯蒂 (腻子替代品)。
ssh-copy-id是一个相当简单的脚本,应该很容易在windows下复制。
如果你忽略了所有的参数处理,error handling等等,这些是来自ssh-copy-id的大部分时间都在做的工作。
GET_ID="cat ${ID_FILE}" { eval "$GET_ID" ; } | ssh ${1%:} "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" || exit 1
使用腻子工具这样的命令应该是等效的(未testing)。
type public_id | plink.exe username@hostname "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys"
如果你想做所有相同的error handling和自动键位置,我相信在Windows下编写一个脚本将是一个棘手的,但肯定是可能的。
ssh-copy-id执行了一些操作(详细信息请参阅手册页 ),但最重要的是将本地公钥文件的内容附加到名为authorized_keys的远程文件中。
您可以通过使用文本编辑器打开密钥文件并粘贴Kittyterminal上的内容来完成此操作。
echo 'long_line_with_contents_of_public_key_file' >> .ssh/authorized_keys
或者,您可以使用WinSCP (使用sftp或scp作为后备)上载文件,并执行与我之前的build议类似的操作,而不会有难看的复制/粘贴。
cat id_rsa.pub >> .ssh/authorized_keys
其中id_rsa.pub是您上传的公钥的文件名。
这些答案并没有帮助我。 我真的不需要任何疯狂的脚本。 我在我的客户机上创build了一个公钥在git bash中,并试图将其复制到VPS。
创build你的公钥后,密钥应该保存为“(无论你开始的文件夹)/。ssh / id_rsa.pub”
所以使用这个命令:
cat ~/.ssh/id_rsa.pub | ssh [email protected] "cat >> ~/.ssh/authorized_keys"
cat ~/.ssh/id_rsa.pub | ssh [email protected] "cat >> ~/.ssh/authorized_keys"
其中user
是你的用户名(有时是“root”,或者你可能设置的任何东西),并且用你的机器/主机/ VPS的IPreplace123.45.67.89
地址。
如果目录.ssh
尚未在主机上创build,请使用这个小的变体:
cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
受zoredache回答的启发,我创build了一系列windows版本的脚本。 不过他们都依赖于plink。 请看看这里
https://github.com/VijayS1/Scripts/blob/master/ssh-copy-id/
我也有一个winscp脚本,可以用作另一个答案。 :)自述文件摘录:
到目前为止尝试的方法:
usage: .\Scriptname [email protected] password [identity file]
usage: .\Scriptname /i:idtest.pub [email protected] /p:password
usage: .\Scriptname -i idtest.pub [email protected] password
# "WinSCP.com" /script=".\Scriptname" /parameter "user[:password]@example.com" "id_rsa.pub" [/log=".\copyssh.log]"
在Windows 7中有一个ssh.exe
这是什么对我有用:
1.创build身份(在Windows上)
c:\>ssh-keygen
在主目录中创build了一个身份文件。 我将公钥的名称改为“id_rsa”
2.将文件复制到目标linux系统,使用ssh Credits来https://serverfault.com/users/984/zoredache作为回答
c:\>ssh user@lnxhost "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys || exit 1" < \\path_to_where_the_file_was_generated_from_ssh_key_gen\id_rsa.pub
注意:由于某些原因,pipe路不适用于我:
# this should work but it didn't work for me type file | ssh user@lnxhost "cat >> /tmp/t.txt"
3.更正linux上的文件windows 上的id_rsa.pub文件是多行的,Linux期望它在一行中,所以我们必须纠正一下。 login到Linux并打开文件:
vi ~/.ssh/authorized_keys
例如:
---- BEGIN SSH2 PUBLIC KEY ---- Comment: "2048-bit RSA, user@winhost" AAAAB3NzaC1yc2EAAAABIwAAAQEAnvYlVooXGoj3+7huZBUqf4wj57r25SHCKiiShyla33 5flX7Rsmb4meExpdh2NzfzffG15xl1wo0xBZ3HdZdqF2GUniEcNbtVjS1FKzQwPfsYPHMC Y58qT0U2ZgK1zsXj2o0D2RWrCv3DFFfwUgNyZRYN2HK32umY6OmGSOVuJvIKhT+X6YaCVy ax3CHv2ByB2OTBl9mh4nrwYAVXToT+X2psBE+MKB5R85lrUGkl3GtymTk10Dvf5O80exdT LFRMvkCA5RAIZgvxMk/bbNaH/0UHQoctX9oaDeKGWUPfVaknFBQdU9009+lK/ocAlKVNHE Qkw+1wuV6dFoT1/hngSw== ---- END SSH2 PUBLIC KEY ----
应该成为
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAnvYlVooXGoj3+7huZBUqf4wj57r25SHCKiiShyla335flX7Rsmb4meExpdh2NzfzffG15xl1wo0xBZ3HdZdqF2GUniEcNbtVjS1FKzQwPfsYPHMCY58qT0U2ZgK1zsXj2o0D2RWrCv3DFFfwUgNyZRYN2HK32umY6OmGSOVuJvIKhT+X6YaCVyax3CHv2ByB2OTBl9mh4nrwYAVXToT+X2psBE+MKB5R85lrUGkl3GtymTk10Dvf5O80exdTLFRMvkCA5RAIZgvxMk/bbNaH/0UHQoctX9oaDeKGWUPfVaknFBQdU9009+lK/ocAlKVNHEQkw+1wuV6dFoT1/hngSw== user@winhost
4.testing一下
c:\>ssh user@lnxhost "ls -al /tmp/"
这应该列出/ tmp的内容而不要求input密码。
如果你正在使用cmder (或msysgit / mingw有scp&ssh),我只是写了一个简单的python脚本。 它可以在这里find: https : //gist.github.com/ceilfors/fb6908dc8ac96e8fc983
示例用法:python ssh-copy-id.py user @ remote-machine。
运行脚本时会提示密码。
我在GitHub上find了一个Windows版本的ssh-copy-id: https : //github.com/zhengyi-yang/ssh-copy-id/tree/master/dist
我做了什么,CygWin在我的Win10上,连接到Linux(根据上面的答案):
– 注意:使用cat,它会自动parsingcygwinpath,以及使用cygwin-linux-folder-structure的任何cygwin命令
1. added c:\cygwin\bin to the environment's Path variable 2. starting cmd.exe (windows commandline) 3. > ssh-keygen -t rsa (just pressing enter till done) 4. > cat ~/.ssh/id_rsa.pub | ssh user@server "umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys" 5. ..enter server password 6. > ssh user@server (testing, not beeing asked for password)
以下步骤可以做到:
STEP-1:生成RSA密钥对
C:\Users\user>ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/user//.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/user//.ssh/id_rsa. Your public key has been saved in /c/Users/user//.ssh/id_rsa.pub. The key fingerprint is: 20:16:9b:0d:00:92:c4:34:99:51:20:b7:ef:50:c4:0f user@localhost
STE2-2:在Windows中相当于ssh-copy-id
C:\Users\user>ssh user@remote "umask 077; test -d .ssh || mkdir .ssh ; cat >> .s sh/authorized_keys || exit 1" < "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys || exit 1" < C:\Users\user\.ssh\id_rsa.pub The authenticity of host 'remote (xx.xx.xxx.xx)' can't be established. RSA key fingerprint is 99:99:73:74:fe:14:bc:91:c8:3b:ac:f4:95:99:4d:06. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'remote,xx.xx.xxx.xx' (RSA) to the list of known hosts. ************************************************************************* This computer system is the property of Sample Corporation and is to be used for business purposes. All information, messages, software and hardware created, stored, accessed, received, or used by you through this system is considered to be the sole property of Sample Corporation and can and may be monitored, reviewed, and retained at any time. You should have no expectation that any such information, messages or material will be private. By accessing and using this computer, you acknowledge and consent to such monitoring and information retrieval. By accessing and using this computer, you also agree to comply with all of Sample Company's policies and standards. ************************************************************************* user@remote's password:[Enter Password for first time]
第3步:无密码authentication工作!
C:\Users\user>ssh user@remote ************************************************************************* This computer system is the property of Sample Corporation and is to be used for business purposes. All information, messages, software and hardware created, stored, accessed, received, or used by you through this system is considered to be the sole property of Sample Corporation and can and may be monitored, reviewed, and retained at any time. You should have no expectation that any such information, messages or material will be private. By accessing and using this computer, you acknowledge and consent to such monitoring and information retrieval. By accessing and using this computer, you also agree to comply with all of Sample Company's policies and standards. ************************************************************************* Last login: Wed Oct 14 14:37:13 2015 from localhost