*新建一台服务器以后要做的事情(实验环境)

1、关闭防火墙和selinux

永久关防火墙

iptables -t filter -F

systemctl stop firewalld

systemctl disable firewalld

systemctl staus firewalld

永久关selinux

vi /etc/selinux/config

把SELINUX=enforcing改成disabled

或用这个命令:sed -ri ‘s/enforcing/disabled/g’ /etc/sysconfig/selinux

setenforce 0

或者配置临时关闭selinux

setenforce 0

然后设置开机挂载,rc.local或者/etc/fstab都可以,可以用mount -a命令验证

iptables -t filter -F
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
sed -ri 's/enforcing/disabled/g' /etc/sysconfig/selinux
setenforce 0

2、改主机名

hostnamectl set-hostname xxxxxx 
hostname 
cat /etc/hostname

3、设置静态IP

nmcli con mod ens33 ipv4.addresses "192.168.1.100/24"
nmcli con mod ens33 ipv4.gateway "192.168.1.1"
nmcli con mod ens33 ipv4.dns "8.8.8.8,8.8.4.4" # 多个dns
nmcli con mod ens33 ipv4.method manual
nmcli con down ens33;nmcli con up ens33

4、配置同步时间NTP

下述步骤一次性粘贴到每个客户端执行即可

# 1、安装chrony
yum -y install chrony
# 2、需改客户端配置文件
mv /etc/chrony.conf /etc/chrony.conf.bak
cat > /etc/chrony.conf << EOF
server ntp1.aliyun.com iburst minpoll 4 maxpoll 10
server ntp2.aliyun.com iburst minpoll 4 maxpoll 10
server ntp3.aliyun.com iburst minpoll 4 maxpoll 10
server ntp4.aliyun.com iburst minpoll 4 maxpoll 10
server ntp5.aliyun.com iburst minpoll 4 maxpoll 10
server ntp6.aliyun.com iburst minpoll 4 maxpoll 10
server ntp7.aliyun.com iburst minpoll 4 maxpoll 10
driftfile /var/lib/chrony/drift
makestep 10 3
rtcsync
local stratum 10
keyfile /etc/chrony.key
logdir /var/log/chrony
stratumweight 0.05
noclientlog
logchange 0.5
 
EOF
# 3、启动chronyd
systemctl restart chronyd.service
systemctl enable chronyd.service
systemctl status chronyd.service
 
# 4、验证
chronyc sources -v  # 结果解析如下图

5、更新源

#换阿里源 
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 
#加epel源 
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 
#更新源 
yum upgrade -y 
# 对于Debian/Ubuntu 
sudo apt update && sudo apt upgrade -y

6、创建密钥对

假设现在新建的是主机B,我们需要从主机A访问主机B

1. 在主机A上生成密钥对

ssh-keygen

生成的密钥对包括公钥(~/.ssh/id_rsa.pub)和私钥(~/.ssh/id_rsa

2. 将公钥从主机A复制到主机B

ssh-copy-id user@host_b

这里的user是主机B上的用户名,host_b是主机B的IP地址或域名。这个命令会提示你输入主机B的密码,并自动将公钥添加到主机B的~/.ssh/authorized_keys文件中。

也可以手动复制公钥。

在主机A上执行以下命令,将公钥复制到剪贴板:

cat ~/.ssh/id_rsa.pub
echo "复制的公钥key一串英文" >> ~/.ssh/authorized_keys

3. 设置主机B的SSH配置

确保~/.ssh目录和authorized_keys文件的权限正确

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

编辑/etc/ssh/sshd_config文件(可选,但推荐检查),确保以下参数被正确设置:

PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

重新启动SSH服务

sudo systemctl restart sshd

4. 从主机A连接到主机B

ssh user@host_b

这样,你就应该可以成功使用SSH密钥对从主机A访问主机B了。如果遇到问题,可以检查SSH连接的详细输出:

ssh -v user@host_b

评论

  1. 1 年前
    2024-5-28 9:49:29

    Hi, this is a comment.
    To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
    Commenter avatars come from Gravatar.

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
下一篇