怎樣無密碼登陸Ubuntu伺服器

1 用ssh-keygen生成一組public key和private key,比如mykey.pub和mykey

2 把public key copy上要登陸的伺服器

cat mykey.pub | ssh my-host 'cat >> ~/.ssh/authorized_keys'

3 如果key有pass phrase,可以用ssh-add

ssh-add mykey

4 現在應該可以不用密碼直接ssh登陸了

ssh my-host

5 如果需要用特定key ssh的話,用 -i 選項

ssh -i mykey my-host

6 如果伺服器用戶名和當前機器用戶名不一樣,在hostname前加”username@”

ssh my-user-name@my-host

7 怎樣管理哪個網站用哪個key

管理網站對應的key,可以用~/.ssh/config,例子如下

# Default settings for all hosts
Host *
  ForwardAgent yes
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/default_key

# GitHub-specific settings
Host github.com example.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_key

Leave a Comment

Your email address will not be published.