ssh 登录方式

ssh 登录方式

1.经典账号密码登录

>>> ssh root@example.com
 root@example.com's password: 

密钥登录

如果生成密钥的过程一路回车,没有出入任何信息(即没有为密钥的私钥设置密码), 那么也可以使用密钥登录(密钥带了账户名)

>>> ssh -i ~/.ssh/id_rsa example.com
 root@example.com's password:

将本机密钥复制到远程

ssh-copy-id 复制 -i:指定端口文件 -p:port 指定端口号

[root@nginx-kafka01 .ssh]# ssh-copy-id -p 22 -i id_rsa.pub root@192.168.2.132
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
#首先在这里第一次上传公钥的时候是需要输入对方机器的密码,后面执行的时候就不需要输入了
root@192.168.2.132's password:  
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh -p '22' 'root@192.168.2.132'"
and check to make sure that only the key(s) you wanted were added

这样会将本机密钥复制到远程机的authorized_keys

posted @ 2024-06-28 16:10  枫奇丶宛南  阅读(414)  评论(0编辑  收藏  举报