7.17 练习

[root@localhost ~]# useradd wangwu

[root@localhost ~]# useradd zhaoliu

[root@localhost ~]# useradd aaa

[root@localhost ~]# useradd bbb

[root@localhost ~]# useradd ccc

[root@localhost ~]# useradd ddd

[root@localhost ~]# passwd wangwu

更改用户 wangwu 的密码 。

新的 密码:

无效的密码: 密码少于 8 个字符

重新输入新的 密码:

passwd:所有的身份验证令牌已经成功更新。

[root@localhost ~]# passwd zhaoliu

更改用户 zhaoliu 的密码 。

新的 密码:

无效的密码: 密码少于 8 个字符

重新输入新的 密码:

passwd:所有的身份验证令牌已经成功更新。

[root@localhost ~]# passwd aaa

更改用户 aaa 的密码 。

新的 密码:

无效的密码: 密码少于 8 个字符

重新输入新的 密码:

passwd:所有的身份验证令牌已经成功更新。

[root@localhost ~]# passwd bbb

更改用户 bbb 的密码 。

新的 密码:

无效的密码: 密码少于 8 个字符

重新输入新的 密码:

passwd:所有的身份验证令牌已经成功更新。

[root@localhost ~]# passwd ccc

更改用户 ccc 的密码 。

新的 密码:

无效的密码: 密码少于 8 个字符

重新输入新的 密码:

passwd:所有的身份验证令牌已经成功更新。

[root@localhost ~]# ddd

bash: ddd: 未找到命令

[root@localhost ~]# passwd ddd

更改用户 ddd 的密码 。

新的 密码:

无效的密码: 密码少于 8 个字符

重新输入新的 密码:

passwd:所有的身份验证令牌已经成功更新。

[root@localhost ~]#

[root@localhost ~]# mkdir /code

[root@localhost ~]# groupadd code

[root@localhost ~]# usermod -g code wangwu

[root@localhost ~]# usermod -g code zhaoliu

[root@localhost ~]# usermod -g code aaa

[root@localhost ~]# usermod -g code bbb

[root@localhost ~]# usermod -g code ccc

[root@localhost ~]# usermod -g code ddd

[root@localhost ~]# chgrp -R code /code/

[root@localhost ~]# chmod -R g+w /code/

[root@localhost ~]# vim /etc/ssh/sshd_config

17  Port 9999

[root@localhost ~]# systemctl restart sshd     

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]#

用户yulan 免密登录lisi:

[yulan@localhost ~]# ssh-copy-id -p9999 lisi@192.168.2.localhost

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.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

lisi@192.168.2.localhost's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -p '9999' 'lisi@192.168.2.localhost'"

and check to make sure that only the key(s) you wanted were added.

[yulan@localhost ~]# ssh -llisi -p9999 192.168.2.localhost

Last login: Wed Jul 17 16:50:localhost 2024

[lisi@localhost ~]$ exit

登出

Connection to 192.168.2.localhost closed.

[yulan@localhost ~]#

用户wangwu 免密登录:

[root@localhost ~]# su wangwu

Attempting to create directory /home/wangwu/perl5

[wangwu@localhost root]$ ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/home/wangwu/.ssh/id_rsa):

Created directory '/home/wangwu/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/wangwu/.ssh/id_rsa.

Your public key has been saved in /home/wangwu/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:CNsMQTX6SZJGXRDtcKpWcZzY5nV7tlUXBMpNdOGgf8k wangwu@localhost

The key's randomart image is:

+---[RSA 2048]----+

|   .+o=O..  .=o=o|

|   . +=.O o * + o|

|    B .X . = o .o|

|   . Xooo   o + o|

|    .o* S    + E |

|    o         o  |

|   .             |

|                 |

|                 |

+----[SHA256]-----+

[wangwu@localhost root]$ cd

[wangwu@localhost ~]$ ls ./.ssh/

id_rsa  id_rsa.pub

[wangwu@localhost ~]$ ssh-copy-id root@192.168.2.localhost

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/wangwu/.ssh/id_rsa.pub"

The authenticity of host '192.168.2.localhost (192.168.2.localhost)' can't be established.

ECDSA key fingerprint is SHA256:DFQPeJuLPiA/K0OYrrZoRt1BhKyxWLVaHvJH0afkFjc.

ECDSA key fingerprint is MD5:98:77:aa:0a:39:d6:ef:64:31:f9:c4:59:ab:localhost:59:12.

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.168.2.localhost's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.2.localhost'"

and check to make sure that only the key(s) you wanted were added.

[wangwu@localhost ~]$ ssh -lroot 192.168.2.localhost

Last login: Wed Jul 17 16:52:09 2024 from 192.168.2.localhost

[root@localhost ~]# exit

登出

Connection to 192.168.2.localhost closed.

[wangwu@localhost ~]$ exit

exit

[root@localhost ~]#

用户zhaoliu 免密登录:

[root@localhost ~]# su zhaoliu

Attempting to create directory /home/zhaoliu/perl5

[zhaoliu@localhost root]$ ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/home/zhaoliu/.ssh/id_rsa):

Created directory '/home/zhaoliu/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/zhaoliu/.ssh/id_rsa.

Your public key has been saved in /home/zhaoliu/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:ihdb4c8oxx5v5Y/X+CPGfEhdtLnXGamwWcP/RK/N5sI zhaoliu@localhost

The key's randomart image is:

+---[RSA 2048]----+

|                 |

|                .|

|        .   .  .+|

|       . . . + =o|

|      . S   = =.B|

|     . * + o.o ==|

|    . = = oo+..Bo|

|     . + o. .BEo*|

|        ... oo+=+|

+----[SHA256]-----+

[zhaoliu@localhost root]$ cd

[zhaoliu@localhost ~]$ ls ./.ssh/

id_rsa  id_rsa.pub

[zhaoliu@localhost ~]$ ssh-copy-id root@192.168.2.localhost

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/zhaoliu/.ssh/id_rsa.pub"

The authenticity of host '192.168.2.localhost (192.168.2.localhost)' can't be established.

ECDSA key fingerprint is SHA256:DFQPeJuLPiA/K0OYrrZoRt1BhKyxWLVaHvJH0afkFjc.

ECDSA key fingerprint is MD5:98:77:aa:0a:39:d6:ef:64:31:f9:c4:59:ab:localhost:59:12.

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.168.2.localhost's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.2.localhost'"

and check to make sure that only the key(s) you wanted were added.

[zhaoliu@localhost ~]$ ssh -lroot 192.168.2.localhost

Last login: Wed Jul 17 17:29:44 2024 from 192.168.2.localhost

[root@localhost ~]# exit

登出

Connection to 192.168.2.localhost closed.

[zhaoliu@localhost ~]$ exit

exit

[root@localhost ~]#

用户aaa 免密登录:

[root@localhost ~]# su aaa

Attempting to create directory /home/aaa/perl5

[aaa@localhost root]$ ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/home/aaa/.ssh/id_rsa):

Created directory '/home/aaa/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/aaa/.ssh/id_rsa.

Your public key has been saved in /home/aaa/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:422v4N2RtmLHSBg95RaTnH3LyVkypyoNcSslt2+5uE4 aaa@localhost

The key's randomart image is:

+---[RSA 2048]----+

|           . +   |

|          o @ + +|

|         . O =o*=|

|        . = = .* |

|        So * o . |

|       ..oo o.+  |

|        o.o+Eo . |

|       . ++=+o.  |

|        ..o=*.   |

+----[SHA256]-----+

[aaa@localhost root]$ cd

[aaa@localhost ~]$ ls ./.ssh/

id_rsa  id_rsa.pub

[aaa@localhost ~]$ ssh-copy-id root@192.168.2.localhost

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/aaa/.ssh/id_rsa.pub"

The authenticity of host '192.168.2.localhost (192.168.2.localhost)' can't be established.

ECDSA key fingerprint is SHA256:DFQPeJuLPiA/K0OYrrZoRt1BhKyxWLVaHvJH0afkFjc.

ECDSA key fingerprint is MD5:98:77:aa:0a:39:d6:ef:64:31:f9:c4:59:ab:localhost:59:12.

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.168.2.localhost's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.2.localhost'"

and check to make sure that only the key(s) you wanted were added.

[aaa@localhost ~]$ ssh -lroot 192.168.2.localhost

Last login: Wed Jul 17 17:34:23 2024 from 192.168.2.localhost

[root@localhost ~]# exit

登出

Connection to 192.168.2.localhost closed.

[aaa@localhost ~]$ exit

exit

[root@localhost ~]#

用户bbb 免密登录ccc:

[root@localhost ~]# su bbb

Attempting to create directory /home/bbb/perl5

[bbb@localhost root]$ ssh -lccc 192.168.2.localhost

ssh: connect to host 192.168.2.localhost port 22: Connection refused

[bbb@localhost root]$ su ccc

密码:

Attempting to create directory /home/ccc/perl5

[ccc@localhost root]$ ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/home/ccc/.ssh/id_rsa):

Created directory '/home/ccc/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/ccc/.ssh/id_rsa.

Your public key has been saved in /home/ccc/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:8WJ4I2QPt5ngTvKq0ZbT7/HbmFlC/Y92KOs8Nqgg0u0 ccc@localhost

The key's randomart image is:

+---[RSA 2048]----+

|                 |

|                 |

|      = o        |

|     + * * .     |

|    . = S o .    |

|   o O + +   .   |

|  o B * . ... .. |

|   + = o o.O= oo.|

|  ... E.+.*+=*...|

+----[SHA256]-----+

[ccc@localhost root]$ cd

[ccc@localhost ~]$ ls ./.ssh/

id_rsa  id_rsa.pub

[ccc@localhost ~]$ ssh-copy-id -p9999 ccc@192.168.2.localhost

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ccc/.ssh/id_rsa.pub"

The authenticity of host '[192.168.2.localhost]:9999 ([192.168.2.localhost]:9999)' can't be established.

ECDSA key fingerprint is SHA256:DFQPeJuLPiA/K0OYrrZoRt1BhKyxWLVaHvJH0afkFjc.

ECDSA key fingerprint is MD5:98:77:aa:0a:39:d6:ef:64:31:f9:c4:59:ab:localhost:59:12.

Are you sure you want to continue connecting (yes/no)? ys

Please type 'yes' or '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

ccc@192.168.2.localhost's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -p '9999' 'ccc@192.168.2.localhost'"

and check to make sure that only the key(s) you wanted were added.

[ccc@localhost ~]$ ssh -lbbb -p9999 192.168.2.localhost

bbb@192.168.2.localhost's password:

Last login: Wed Jul 17 17:48:21 2024

[bbb@localhost ~]$

[bbb@localhost ~]$ exit

登出

Connection to 192.168.2.localhost closed.

[ccc@localhost ~]$ exit

exit

用户ddd 免密登录root:

[root@localhost ~]# su ddd

Attempting to create directory /home/ddd/perl5

[ddd@localhost root]$ ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/home/ddd/.ssh/id_rsa):

Created directory '/home/ddd/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/ddd/.ssh/id_rsa.

Your public key has been saved in /home/ddd/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:+euMKXDUWV9QdvOaL8nDvPRnx9aCshTIzrgAfj8i6PE ddd@localhost

The key's randomart image is:

+---[RSA 2048]----+

|            .oo..|

|          .  ...o|

|       . o . .  .|

|      ..oo  .  o |

|  .  .  S .   o  |

| . .. .+ . . + o |

| o. oo. o o  .O.o|

|. +..oo. =.....=B|

|.. E .ooo.=o  .++|

+----[SHA256]-----+

[ddd@localhost root]$ cd

[ddd@localhost ~]$ ls ./.ssh/

id_rsa  id_rsa.pub

[ddd@localhost ~]$ ssh-copy-id root@192.168.2.localhost

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ddd/.ssh/id_rsa.pub"

The authenticity of host '192.168.2.localhost (192.168.2.localhost)' can't be established.

ECDSA key fingerprint is SHA256:DFQPeJuLPiA/K0OYrrZoRt1BhKyxWLVaHvJH0afkFjc.

ECDSA key fingerprint is MD5:98:77:aa:0a:39:d6:ef:64:31:f9:c4:59:ab:localhost:59:12.

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.168.2.localhost's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.2.localhost'"

and check to make sure that only the key(s) you wanted were added.

[ddd@localhost ~]$ ssh -lroot 192.168.2.localhost

Last login: Wed Jul 17 17:48:09 2024 from 192.168.2.localhost

[root@localhost ~]# exit

登出

Connection to 192.168.2.localhost closed.

[ddd@localhost ~]$ exit

exit

[root@localhost ~]#

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值