远程连接ubuntu服务器设置ssh免密码登陆的简单方式

0 篇文章 0 订阅

在工作中我们经常需要登陆服务器,但是登陆服务器就需要输入密码,这里介绍一种简单的免密码的登陆方式,这里默认服务器已经安装了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 keys
eric@10.18.96.116's password:

Number of key(s) added: 1

Now 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 keys
eric@10.18.96.116's password:

Number of key(s) added:        1

Now 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://www.jianshu.com/p/0f2fb935a9a1

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

农民小飞侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值