Not Fibonacci(矩阵连乘)
1911
2022-08-22
远程连接ubuntu服务器设置ssh免密码登陆的简单方式
在工作中我们经常需要登陆服务器,但是登陆服务器就需要输入密码,这里介绍一种简单的免密码的登陆方式,这里默认服务器已经安装了ssh server,本地也安装好了ssh client,我用的是mac,本地无须安装ssh client,只需要服务器安装ssh server就行了:
sudo apt-get install openssh-server
首先生成ssh key,如果已经生成了,则无须重复生成:
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
如果已经生成了,那么进入cd ~/.ssh cat id_rsa.pub查看
然后:ssh-copy-id 你的用户名@你的IP
例如:
(base) ➜ ~ ssh-copy-id eric@10.18.96.116/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/eric/.ssh/id_ed25519.pub"The authenticity of host '10.18.96.116 (10.18.96.116)' can't be established.ECDSA key fingerprint is SHA256:zRR/HcgYecAov/tjE1NZZgXnw4CK42GjgrXAZN2Wxq8.Are you sure you want to continue connecting (yes/no)? yes/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 keyseric@10.18.96.116's password:Number of key(s) added: 1Now try logging into the machine, with: "ssh 'eric@10.18.96.116'"and check to make sure that only the key(s) you wanted were added.(base) ➜ ~ ssh-copy-id eric@10.18.96.116/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/admin/.ssh/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 keyseric@10.18.96.116's password:Number of key(s) added: 1Now try logging into the machine, with: "ssh 'eric@10.18.96.116'"and check to make sure that only the key(s) you wanted were added.
会自动把公钥传输到服务端的$HOME/.ssh/authorized_keys文件夹里,这样就把公钥上传到服务器上了,全程无须手动复制,是不是很简单呢。
每次登录就不用输密码了
参考文献
[1]. VScode Remote 远程开发与调试. https://jianshu.com/p/0f2fb935a9a1
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~