Linux ssh 免密 别名登陆

在当前用户下

MacBook-Pro-M:~ xuxiansheng$ cd   // 当前目录cd 回到当前用户目录下
MacBook-Pro-M:~ xuxiansheng$ ssh-keygen -t rsa   //输入命令后连续三次回车
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/xuxiansheng/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/xuxiansheng/.ssh/id_rsa.
Your public key has been saved in /Users/xuxiansheng/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:xlTSo5t3259M/nDGTY6Wj7+97G9XdeggfkoMImHeQeGx0 xuxiansheng@MacBook-Pro-M.local
The key's randomart image is:
+---[RSA 2048]----+
|       .+.Z .  ..|
|       + =do ....|
|      . O.o.  .+ |
|       *.=    . .|
|        Do     ..|
|       .o . .  *o|
|         . . o=.N|
|            ..**=|
|              o%&|
+----[SHA256]-----+
MacBook-Pro-M:~ xuxiansheng$ // 三次回车后的样子

之后进入到.ssh文件夹下,就能看到生成的公钥和私钥文件

MacBook-Pro-M:~ xuxiansheng$ cd .ssh/
MacBook-Pro-M:.ssh xuxiansheng$ ll
total 48

-rw-------  1 xuxiansheng  staff  1843 11 18 16:24 id_rsa
-rw-r--r--  1 xuxiansheng  staff   413 11 18 16:24 id_rsa.pub
MacBook-Pro-M:.ssh xuxiansheng$

接下来通过命令 ssh-copy-id root@192.168.2.200 将公钥文件发送给服务器,弹出的框中输入服务器机器密码即可

MacBook-Pro-M:.ssh xuxiansheng$ ssh-copy-id root@192.22.168.110 -p 22
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/xuxiansheng/.ssh/id_rsa.pub"
The authenticity of host '[192.22.168.110]:22 ([192.22.168.110]:22)' can't be established.
RSA key fingerprint is SHA256:EXpOj8VFXnE223dfp3fFh8WpDUpMWjXRzxd5C8Tnx14.
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
root@192.22.168.110's password: 

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh -p '22' 'root@192.22.168.110'"
and check to make sure that only the key(s) you wanted were added.

MacBook-Pro-M:.ssh xuxiansheng$ 

ssh免密登陆

MacBook-Pro-M:.ssh xuxiansheng$ ssh root@192.22.168.110 -p 22
Last login: Wed Nov 18 16:39:08 2020 from 192.168.1.11
 Welcome xuxiansheng@MacBook-Pro-M.local ! 
[root@CY-DB-1_192.22.168.110 ~]# 
[root@CY-DB-1_192.22.168.110 ~]# //登陆成功

设置别名

vim .bash_profile //修改文件
// 添加下面语句
alias locahost110='ssh root@192.22.168.110 -p 22 -i ~/.ssh/id_rsa'
// 让修改文件生效
source .bash_profile



MacBook-Pro-M:~ xuxiansheng$ locahost110 

Welcome to Alibaba Cloud Elastic Compute Service !

Activate the web console with: systemctl enable --now cockpit.socket

Last login: Wed Nov 18 16:15:19 2020 from 192.168.1.110
[root@iZ28uxyhlwdZ ~]# ll
总用量 0
drwxr-xr-x 4 root root 40 9月  16 10:09 logs
[root@iZ28uxyhlwdZ ~]# cd /
[root@iZ28uxyhlwdZ /]# ll
总用量 36
lrwxrwxrwx.   1 root root    7 5月  11 2019 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 9月   8 18:02 boot
-rw-r--r--    1 root root 1706 9月   9 13:57 ccc
drwxr-xr-x   19 root root 2980 9月  16 11:24 dev
drwxr-xr-x. 105 root root 8192 11月  5 17:22 etc
drwxr-xr-x.   2 root root    6 5月  11 2019 home
lrwxrwxrwx.   1 root root    7 5月  11 2019 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 5月  11 2019 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 5月  11 2019 media
drwxr-xr-x   59 root root 4096 9月  16 13:38 mnt
drwxr-xr-x.   3 root root   24 9月   8 18:05 opt
dr-xr-xr-x  244 root root    0 9月  16 11:24 proc
dr-xr-x---.  11 root root 4096 11月 18 16:21 root
drwxr-xr-x   32 root root  960 9月  16 11:44 run
lrwxrwxrwx.   1 root root    8 5月  11 2019 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 5月  11 2019 srv
dr-xr-xr-x   13 root root    0 9月  16 19:24 sys
drwxrwxrwt.   5 root root 4096 11月 18 16:48 tmp
drwxr-xr-x.  12 root root  144 9月   8 17:11 usr
drwxr-xr-x.  21 root root 4096 9月  16 11:24 var
[root@iZ28uxyhlwdZ /]# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值