怎样无密码登陆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.