linux常用操作实例

2021/3/24 linux常用操作

# Mysql添加用户

create user 'sankang'@'%' identified by '123456'; 创建用户

grant all privileges on lohas.* to 'sankang'@'%' with grant option; 赋予某个数据库

FLUSH PRIVILEGES;  刷新用户权限

show grants for 'sankang'@'%'; -- 展示用户权限

drop user 'sankang'@'%';

select host,user,plugin,authentication_string from mysql.user;  
1
2
3
4
5
6
7
8
9
10
11

# 开启Navicat的ssh远程数据库登录

第一步:进入/etc/ssh/sshd_config文件中

第二步:UseDNS no
       AddressFamily inet
       SyslogFacility AUTHPRIV
       PermitRootLogin yes
       PasswordAuthentication yes
       PermitEmptyPasswords no 
1
2
3
4
5
6
7
8

# 在ftp添加用户并添加指定权限

# 创建sankang用户 且 创建文件目录
useradd -g www -m -s /bin/bash sankang

# 给 sankang 用户设置密码
passwd sankang

# 进入指定目录
cd /home/wwwroot/lohas.youthup.cn/public/static

# 将目录/api 及其下面的所有文件、子目录文件属主改为www,属组改为www
chown -R www:www api

# 赋予 www组的 api目录 0775权限
chmod -R 0775 api

# 设置当前用户登录的直接目录
/etc/passwd

# 添加新用户
useradd xxx

# 添加新群组
groupadd users

# 将用户xxx加入 youthup 群组
usermod -G youthup xxx

# 查看该用户信息
grep 'zzb' /etc/passwd /etc/group /etc/shadow /etc/gshadow

# 一般给除所有者以外的640权限
chmod 640 /www/wwwroot/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# http转换https

第一步:先申请免费证书
第二步:选择nginx下载证书
第三步:去/usr/local/nginx/conf/vhost中设置ssl 与 fastcgi_pass unix:/tmp/php-cgi.sock; 运行环境
location ~ \.php$ {
    root /home/wwwroot/port.youthup.cn/public;
    fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
}
第四步:去服务器->安全组->开启443端口
1
2
3
4
5
6
7
8
9
10

# 更改phpMyAdmin的数据库密码

# 结束当前正在运行的mysql进程。
第一步:执行/etc/init.d/mysql stop

# 用mysql安全模式运行并跳过权限验证。
第二步:执行 /usr/bin/mysqld_safe --skip-grant-tables

第三步:登录你的PHPmyadmin,这时候,你随便写密码,就可以进入。

第四步:查看mysql数据库里面的user表,就可以看到password字段。

第五步:把新密码写入。注意,密码需要password加密 (加密方式为 mysql5 全部换成大写)# 第二种更改数据库密码的方式
set password for root@localhost = password('123456');

# 导出数据库命令行
mysqldump -u root -p -h 192.168.50.79 --complete-insert --databases drainage > /home/data/drainage.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# 项目版本切换

# 项目版本设置
/usr/local/nginx/conf

# 启动php7.1 ( 一定要先启用 )
/usr/local/php71/sbin/php-fpm

# 检查所有进程
ps -ef | grep php

fastcgi_pass   127.0.0.1:9000;  // 7.1版本
fastcgi_pass  unix:/tmp/php-cgi.sock;   // 默认版本(5.6)

location ~ \.php$ {
    root           /home/wwwroot/doc.youthup.cn;
    
    # PHP 5.6
    # fastcgi_pass   unix:/tmp/php-cgi.sock;
    # include        fastcgi.conf;

    # PHP 7.1
    fastcgi_pass 127.0.0.1:9000;
    include        fastcgi_params;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

# 赋予权限
chown -R www:www /home/wwwroot/doc.youthup.cn
# 给文件赋予权限
chmod 777 file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31