记录服务器管理和安全工作方面上的一些笔记

0x03 git 安全管理

  • 创建一个 git 用户专门用以 git 使用

    1
    sudo adduser git
  • 禁用 git 的 shell 登陆, 上面一行是修改之前, 后面一行是修改之后

    1
    2
    3
    4
    cat /etc/passwd | grep git
    git:x:1000:1000:,,,:/home/git:/bin/bash
    cat /etc/passwd | grep git
    git:x:1000:1000:,,,:/home/git:/usr/bin/git-shell
  • git 用户的 .ssh 文件夹的权限情况 (700)

    1
    2
    /home/git# ls -al
    drwx------ 2 git git 4096 Jul 19 10:17 .ssh
  • authorized_keys 的权限情况 (600)

    1
    2
    /home/git/.ssh# ls -l
    -rw------- 1 git git 1933 Jul 19 10:15 authorized_keys
  • 仓库文件的用户和用户组 (git:git)

    1
    2
    srv# ls -l
    drwxr-xr-x 7 git git 4096 Jul 4 17:04 web
  • 仓库地址的格式

    1
    git@server:/path/to/file

0x02 创建新用户, 并且使用 public key 登陆

在 0x01 之前, 进行这一步操作

  • 添加用户

    1
    sudo adduser newuser
  • 在这个用户的主目录下, 将 ssh 的 public key 添加进来

    1
    2
    3
    4
    5
    6
    tree
    .
    ├── authorized_keys2
    ├── keyOne.pub
    ├── keyTwo.pub
    └── keyThree.pub
  • 添加一个 key 到 authorized_keys2 的方法是

    1
    echo key >> authorized_keys2
  • 从本地机器 copy 文件到远程机器, 注意权限问题

    1
    scp /path/to/localfile username@server:/path/to/destination
  • 从远程机器 copy 文件到本地机器, 注意权限问题

    1
    scp username@server:/path/to/file /path/to/localDestination

0x01 禁用 root 登陆

修改配置文件, 禁用 root 用户登陆, 同时禁用密码登陆

  • 配置文件的路径在这里

    1
    cd /etc/ssh/
  • 备份 config 文件

    1
    cp sshd_config sshd_config.bak
  • 修改过后的文件

1
2
3
4
5
6
7
8
9
diff sshd_config.bak sshd_config
85c85
< PermitRootLogin yes
---
> PermitRootLogin no
87c87
< PasswordAuthentication yes
---
> PasswordAuthentication no

0x00 MySQL 数据库管理

在服务器上创建一个数据库, 以及创建用户和密码, 授予数据库的权限给这个用户

  • user local login

    1
    2
    3
    CREATE DATABASE dbName;
    CREATE USER 'userName'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON dbName.* TO 'userName'@'localhost';
  • user remote login

    1
    2
    3
    CREATE DATABASE dbName;
    CREATE USER 'userName'@'%' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON dbName.* TO 'userName'@'%';
  • remote permissions

    1
    2
    REVOKE ALL PRIVILEGES ON dbName.* FROM 'userName'@'localhost';
    REVOKE ALL PRIVILEGES ON dbName.* FROM 'userName'@'%';