免密登录的步骤
步骤 1: 生成 SSH 密钥对
ssh-keygen -t rsa
提示解释:
当提示 Enter file in which to save the key 时,直接按 Enter 使用默认路径(~/.ssh/id_rsa)。
如果不想设置密钥密码,直接按两次 Enter 跳过。
此操作会在 ~/.ssh/ 目录下生成两个文件:
私钥:id_rsa(本地使用,不能泄露)。
公钥:id_rsa.pub(需要放置到远程服务器)。
步骤 2: 将公钥复制到远程服务器
ssh-copy-id username@remote_host
参数解释:
username:远程服务器的用户名。root
remote_host:远程服务器的 IP 地址或域名。
系统会提示输入远程服务器的密码,验证通过后,会自动将本地公钥添加到远程服务器的 ~/.ssh/authorized_keys 文件中。
                    
                
                
            
        
浙公网安备 33010602011771号