linux- ssh-keygen

1.支持免密访问

生成公钥

ssh-keygen -t rsa -C "Qin Feng" 

连续3个回车,最后得到了两个文件:id_rsaid_rsa.pub,在文件夹$ ~/.ssh文件夹下面


公钥添加到authorized_keys中:cd /home/roaddb/.ssh  &&  cat id_rsa.pub >> authorized_keys
注意权限:chmod 700 .ssh ,chmod 600 .ssh/authorized_keys

【sudo权限免密】

切换到root下修改:sudo su

chmod u+w /etc/sudoers
vi /etc/sudoers

  例:# User privilege specification
        root    ALL=(ALL:ALL) ALL

     # Members of the admin group may gain root privileges
     %admin ALL=(ALL) ALL

    # Allow members of group sudo to execute any command
    %sudo    ALL=(ALL:ALL) ALL
    user ALL=(ALL) NOPASSWD:ALL
    www-data ALL=(ALL) NOPASSWD:ALL

chmod u-w /etc/sudoers

公钥添加到authorized_keys到文件中之后仍无法免密登陆

同样的,检查目录和文件权限,确保.ssh目录权限为700authorized_keys文件权限为600

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
原文地址:https://www.cnblogs.com/ting152/p/12516789.html