Linux一键设置SSH端口,设置秘钥登录

设置秘钥

mkdir -p ~/.ssh
echo "公钥内容" > ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
sed -r -i '/RSAAuthentication/d' /etc/ssh/sshd_config
sed -r -i '/PubkeyAuthentication/d' /etc/ssh/sshd_config
sh -c "echo 'RSAAuthentication yes' >> /etc/ssh/sshd_config"
sh -c "echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config"
service sshd restart

禁用密码登录

sed -r -i '/PasswordAuthentication/d' /etc/ssh/sshd_config
sh -c "echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config"
service sshd restart

修改端口(一键修改为 29032)

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak;
sed -r -i '/Port/d' /etc/ssh/sshd_config
sh -c "echo 'Port 29032' >> /etc/ssh/sshd_config"
service sshd restart

一键设置

mkdir -p ~/.ssh
echo "公钥内容" > ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
sed -r -i '/RSAAuthentication/d' /etc/ssh/sshd_config
sed -r -i '/PubkeyAuthentication/d' /etc/ssh/sshd_config
sh -c "echo 'RSAAuthentication yes' >> /etc/ssh/sshd_config"
sh -c "echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config"
sed -r -i '/PasswordAuthentication/d' /etc/ssh/sshd_config
sh -c "echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak;
sed -r -i '/Port/d' /etc/ssh/sshd_config
sh -c "echo 'Port 29032' >> /etc/ssh/sshd_config"
service sshd restart

给TA打赏
共{{data.count}}人
人已打赏
Linux运维

Linux修改SSH端口并设置秘钥登录

2023-3-16 11:59:48

字体

一款粗壮的圆角美术中文字体:荆南缘默体

2022-8-12 11:46:40

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
搜索