ssh 密钥连接
为什么要使用 ssh 密钥 进行连接服务器?? 这样连接 更安全, 也可以做到无需密码连接 使用步骤 本地客户端创建密钥 ssh-keygen # 输入生成的密钥文件名 Generating public/private rsa key pair. Enter file in which to save the key (~/.ssh/id_rsa): # 会生成 id_rsa 和 id_rsa.pub 文件 # 输入连接的密码(此密码是用于本地用户连接而设定的, 只要使用了密钥连接服务器就默认无需再输入密码连接) # 如果为空, 无需密码 Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in ~/.ssh/id_rsa. Your public key has been saved in ~/.ssh/id_rsa.pub. The key fingerprint is: SHA256:cdoRGC7IV2+vvtFzPjQAZKqun5WUIZx7Zo6dBp0spGY vm465564@root The key's randomart image is: +---[RSA 3072]----+ | o++ | | . o +.+.. | | o B = =. | | + B X o. | | E = S . .. | | o . @ o o o | | o B o o... | | . + . . +. | | ..o o. .. | +----[SHA256]-----+ 将 id_rsa.pub 文件的内容复制到 服务器 ~/.ssh/authorized_keys 进行连接服务器 ssh -p 22 username@host -i ~/.ssh/id_rsa # 如果创建密钥的时候设定了密码, 此处需要的密码是创建密钥的时候的密码, 不是服务器密码