Skip to content

Instantly share code, notes, and snippets.

@shui
Last active June 11, 2017 07:55
Show Gist options
  • Save shui/21bd12e03e8a2902e46e45ca8d5b2cfa to your computer and use it in GitHub Desktop.
Save shui/21bd12e03e8a2902e46e45ca8d5b2cfa to your computer and use it in GitHub Desktop.
设置ssh远程登录远程主机、ssh别名

SSH alias

编辑config文件(vim ~/.ssh/config ),加入如下:

Host alias
    HostName        192.168.6.66
    Port            22
    User            name
    IdentityFile    ~/.ssh/id_rsa

设置ssh远程登录远程主机

$ ssh-keygen -t rsa -b 4096
$ scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/

登入远程主机,在 ~/.ssh/下执行如下:

$ cat id_dsa.pub >> ~/.ssh/authorized_keys

设置权限:

$ sudo chmod 600 ~/.ssh/authorized_keys
$ sudo chmod 700 -R ~/.ssh

禁止密码登录

修改 /etc/ssh/sshd_config:

PubkeyAuthentication no

重启ssh服务(service sshd restart)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment