使用ssh-keygen和ssh-copy-id三步實現SSH無密碼登陸 和ssh經常使用命令

ssh-keygen  產生公鑰與私鑰對.ssh

ssh-copy-id 將本機的公鑰複製到遠程機器的authorized_keys文件中,ssh-copy-id也能讓你有到遠程機器的home, ~./ssh , 和 ~/.ssh/authorized_keys的權利ide


第一步:在本地機器上使用ssh-keygen產生公鑰私鑰對.net

  1. zhz@zhz:~/$ ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/zhz/.ssh/id_rsa):
  2. Enter passphrase (empty for no passphrase): [Press enter key
  3. same passphrase again: [Pess enter key]
  4. Your identification has been saved in /home/zhz/.ssh/id_rsa.
  5. Your public key has been saved in /home/zhz/.ssh/id_rsa.pub.

第二步:用ssh-copy-id將公鑰複製到遠程機器中get

  1. zhz@zhz:~$  ssh-copy-id -i .ssh/id_rsa.pub  用戶名字@192.168.x.xxx
     

注意: ssh-copy-id 將key寫到遠程機器的 ~/ .ssh/authorized_key.文件中it

第三步: 登陸到遠程機器不用輸入密碼io

  1. zhz@zhz:~$  ssh 用戶名字@192.168.x.xxx
相關文章
相關標籤/搜索