linux中ssh远程登陆

server端:

root@server /# hostnamectl set-hostname server.example.com

root@server \~# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

valid_lft forever preferred_lft forever

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000

link/ether 00:0c:29:b1:c7:29 brd ff:ff:ff:ff:ff:ff

altname enp3s0

inet 172.25.254.100/24 brd 172.25.254.255 scope global noprefixroute ens160

valid_lft forever preferred_lft forever

inet6 fe80::20c:29ff:feb1:c729/64 scope link noprefixroute

valid_lft forever preferred_lft forever

root@server \~# useradd timinglee

root@server \~# echo 123456 | passwd --stdin timinglee

更改用户 timinglee 的密码 。

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

root@server \~# systemctl stop firewalld

root@server \~# systemctl disable firewalld

确保只有root用户和timinglee用户可以被登录:

root@server \~# vim /etc/ssh/sshd_config

修改允许登录的账户

#LoginGraceTime 2m

PermitRootLogin yes

#StrictModes yes

#MaxAuthTries 6

#MaxSessions 10

AllowUsers timinglee root

cilent端:

root@client /# hostnamectl set-hostname client.example.com

root@client \~# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

valid_lft forever preferred_lft forever

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000

link/ether 00:0c:29:50:6d:df brd ff:ff:ff:ff:ff:ff

altname enp3s0

inet 172.25.254.200/24 brd 172.25.254.255 scope global noprefixroute ens160

valid_lft forever preferred_lft forever

inet6 fe80::20c:29ff:fe50:6ddf/64 scope link noprefixroute

valid_lft forever preferred_lft forever

制作cilent端的公私钥对:

root@client \~# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa

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

The key fingerprint is:

SHA256:EYGqkroNQD+sKOWkwA+S1/GomvnldO/19a4nlZq53fg root@client.example.com

The key's randomart image is:

+---RSA 3072----+

| .o. |

| . . |

| . .. . |

|o.o..+ . |

|=++=o . S .|

|B*=.. ..|

|*oo.o . . =. |

|o* + . . . . =ooo|

|=oo . .o ..+BE|

+----SHA256-----+

将公钥上传至server端:

root@client \~# ssh-copy-id root@172.25.254.100

/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

root@172.25.254.100's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'root@172.25.254.100'"

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

实现cilent端的免密登录:

root@client \~# ssh -l root 172.25.254.100

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

Register this system with Red Hat Insights: insights-client --register

Create an account or view all your systems at https://red.ht/insights-dashboard

Last login: Sat Apr 20 18:19:24 2024 from 172.25.254.200

相关推荐
凡人叶枫10 小时前
Effective C++ 条款07:为多态基类声明 virtual 析构函数
linux·c语言·开发语言·c++
凡人叶枫10 小时前
Effective C++ 条款10:令 operator= 返回一个 reference to *this
java·linux·服务器·开发语言·c++·effective c++
某林21210 小时前
Isaac Sim 5.1.0 无头服务器部署与 RTX 显存段错误排障全记录
运维·服务器·docker·容器·isaac
|_⊙10 小时前
Linux 中断
linux
m0_7381207210 小时前
Docker 环境下 Vulfocus 靶场搭建全流程(附镜像源问题解决方案)
运维·服务器·网络·安全·docker·容器
Gauss松鼠会11 小时前
【GaussDB】GaussDB SMP特性调优详解
java·服务器·前端·数据库·sql·算法·gaussdb
枫叶梨花11 小时前
Dify 离线安装 OpenAI API Compatible 插件踩坑记
服务器·人工智能
Championship.23.2411 小时前
Linux 3.0 音频机制深度解析:ALSA基础架构与传统音频驱动模型
linux·运维·音视频·alsa
Yukinaaaa11 小时前
以“轮盘数组”思维彻底搞懂并实现阻塞队列
java·服务器·ide·安全·javaee·阻塞队列·轮盘数组
Tian_Hang11 小时前
Linux基础知识(四)
linux·ide·驱动开发·计算机视觉·硬件工程·动画