SSH 服务配置

服务端

启用使用密钥登录

  • 登录到服务器
  • 检查是否存在.ssh文件夹,如果没有则创建该文件夹

    $ mkdir ~/.ssh
    $ chmod 700 ~/.ssh

  • 检查公钥列表文件是否存在,如果没有则创建该文件

    $ touch ~/.ssh/authorized_keys
    $ chmod 600 ~/.ssh/authorized_keys

  • 将客户端公钥添加到公钥列表,也就是将客户端"~/.ssh/id_rsa.pub"文件中的内容添加到authorized_keys文件的最后一行。
  • 编辑 /etc/ssh/sshd_config 文件,

    PubkeyAuthentication yes
    PasswordAuthentication no

    #注意是否允许Root登录
    PermitRootLogin yes

  • 重启ssh服务

    service sshd restart

客户端

SSH的快捷登录

编辑~/.ssh/config 文件, 并添加以下内容:

Host example
HostName 192.168.1.125
Port 22
User root

命令行中使用以下方式登录

$ ssh example

猜你喜欢

转载自www.cnblogs.com/michaelluthor/p/9297716.html