我透過 SSH + 密碼使用 Putty 連接到我的網頁伺服器,並希望產生一對金鑰來為我登入。不幸的是,該命令不知何故“卡住”了..正如您在螢幕截圖
為什麼會發生這種情況?
答案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!"