配置SSH密钥认证
配置Linux公私钥
- 使用SSH远程登录工具,以系统用户登录Linux操作系统命令行界面。
- 执行如下命令生成公私钥对。
1ssh-keygen -t rsa -b 4096
过程中需要:
- (可选)输入保存的文件名,默认会在/userhome/.ssh/id_rsa目录下保存为“id_rsa”(私钥)和“id_rsa.pub”(
公钥 )文件。 - (可选)设置密钥的密码口令。
回显信息如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Generating public/private rsa key pair. Enter file in which to save the key (/userhome/.ssh/id_rsa): /root/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /userhome/.ssh/id_rsa. Your public key has been saved in /userhome/.ssh/id_rsa.pub. The key fingerprint is: SHA256:g8T/XaRUqANpuIjxnI34In89+R68QckZPw7eyEaCU+o root@host11 The key's randomart image is: +---[RSA 4096]----+ | . . .. | | . .. + .. | | * =+o.. .. . | | o *=o+ =o. o | | .+ o S o.. . | |. .... B B o . | | o .E. .O + . | | . . +. + | | . ++ | +----[SHA256]-----+
- (可选)输入保存的文件名,默认会在/userhome/.ssh/id_rsa目录下保存为“id_rsa”(私钥)和“id_rsa.pub”(
- 执行如下命令将公钥文件上传到节点服务器。
1ssh-copy-id -i /userhome/.ssh/id_rsa.pub root@Server IP
- /userhome/.ssh/id_rsa.pub为生成的公钥文件,其中/userhome/(root用户为/root/,普通用户为/home/普通用户名/)请根据实际替换。
- Server IP为节点服务器IP地址,请根据实际替换。
过程中需要输入节点服务器对应用户的密码。
父主题: 常用操作