我使用 Putty 通过 SSH + 密码连接到我的网络服务器,并想生成一对密钥来为我登录。不幸的是,命令不知何故“卡住了”。正如您在截屏
为什么会发生这种情况?
答案1
看起来您首先要连接到远程服务器,然后生成密钥。不要这样做!您的私钥永远不应离开本地系统。您应该使用以下方法在本地生成密钥:普蒂根,然后将生成的公钥放入authorized_keys
远程主机上的文件中。
答案2
这是我用来生成 SSH 密钥的脚本。试试看吧。
#!/bin/sh
KEY="$HOME/.ssh/id_dsa.pub"
if [ ! -f ~/.ssh/id_dsa.pub ];then
ssh-keygen -t dsa -b 1024 -f ~/.ssh/id_dsa -N ''
fi
if [ -z $1 ];then
echo " "
echo "Usage: $0 {[email protected]}"
echo " "
echo " The 'user' is the remote user account allowed to authenticate to"
echo " the 'remote.host'."
echo " "
echo " This ssh connection is used once to copy your key to the 'remote.host'"
echo " "
exit
fi
echo "Sending your key to $1... "
KEYCODE=`cat $KEY`
ssh -q $1 "mkdir ~/.ssh 2>/dev/null; chmod 700 ~/.ssh; echo "$KEYCODE" >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys"
echo "done!"