ssh-keygen ssh-copy-id 无密码登陆

本文介绍如何使用ssh-keygen和ssh-copy-id实现Ubuntu系统的无密码登录。通过创建公钥和私钥,并将公钥复制到远程服务器的authorized_keys文件中,可以简化远程登录流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

ssh-keygen ssh-copy-id 无密码登陆

分类: Ubuntu使用点滴 Android开发 Linux资源 1301人阅读 评论(0) 收藏 举报

进行android开发经常需要登录远程ubuntu server服务器进行编译查看代码等,每次都需要输入密码,很烦人。

使用 ssh-keygen和ssh-copy-id配置一下就可以无需输入密码直接登录服务器了。

ssh-keygen 创建公钥和密钥。
ssh-copy-id 把本地主机的公钥复制到远程主机的authorized_keys文件上。
ssh-copy-id 也会给远程主机的用户主目录(home)和~/.ssh, 和~/.ssh/authorized_keys设置合适的权限 。

 

user@machine:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
43:c6:7d:c4:9c:85:bd:8f:f0:5a:b7:8b:37:e6:e9:12 user@machine
The key's randomart image is:
+--[ RSA 2048]----+
|           o.=.  |
|       . . .= .  |
|        + . .  . |
|       o   .. .  |
|        S    o o |
|         .   E+ o|
|             o...|
|            ...=.|
|             .*=o|
+-----------------+
user@machine:~$ 
user@machine:~$ ls -l .ssh/
total 12
-rw------- 1 user user 1679 Sep  4 16:34 id_rsa
-rw-r--r-- 1 user user  393 Sep  4 16:34 id_rsa.pub
-rw-r--r-- 1 user user  222 Sep  3 13:03 known_hosts
user@machine:~$ ssh-copy-id -i .ssh/id_rsa.pub user@172.16.2.15
user@172.16.2.15's password: 
Now try logging into the machine, with "ssh 'user@172.16.2.15'", and check in:

  ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

user@machine:~$ ssh user@172.16.2.15

 

 如果有端口号的话:

ssh-copy-id -i ~/.ssh/id_rsa.pub  -p 20022 test@192.168.3.2

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值