涛子 - 简单就是美

成单纯魁增,永继振国兴,克复宗清政,广开家必升

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1. 生成sshkey

ssh-keygen -f root.pem -N '' -C 'root@local'
ssh-keygen -f ansible.pem -N '' -C 'ansible@local'
ssh-keygen -f app.pem -N '' -C 'app@local'

2. 用户ansible

useradd ansible
mkdir -p /home/ansible/.ssh && chmod 700 /home/ansible/.ssh

cat > /home/ansible/.ssh/authorized_keys <<EOF
ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ansible@local
EOF

chmod 600 /home/ansible/.ssh/authorized_keys
chown -R ansible:ansible /home/ansible/.ssh

3. 用户app

useradd app
mkdir -p /home/app/.ssh && chmod 700 /home/app/.ssh

cat > /home/app/.ssh/authorized_keys <<EOF
ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx app@local
EOF

chmod 600 /home/app/.ssh/authorized_keys
chown -R app:app /home/app/.ssh

4. 部署目录

mkdir -p /opt/app && chown -R app:app /opt/app

5 变更ssh端口29922 (略)

6. sudo

gpasswd -a ansible wheel
usermod -a -G wheel app
chmod 744 /usr/bin/su

# 禁止切换root
Cmnd_Alias DISABLE_SU = /usr/bin/su, /bin/bash

7. 登录

ssh -i root.pem root@srv-001 -p 29922
ssh -i ansible.pem ansible@srv-001 -p 29922
ssh -i app.pem app@srv-001 -p 29922
posted on 2022-12-13 16:49  北京涛子  阅读(37)  评论(0编辑  收藏  举报