Ubuntu 初始化配置

更新源

       备份源:sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

        sudo vim /etc/apt/sources.list          

        复制阿里源

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

中国科技大学源:USTC Open Source Software Mirror

         执行指令 更新源:sudo apt-get update

        更新软件:sudo apt-get dist-upgrade 

                          sudo apt-get upgrade

修改主机名

        主机名存放路径:/etc/hostname

安装GIT

        执行指令:apt-get install git

生成私钥

        执行指令:ssh-keygen  一路回车(最简单生成)

安装nginx

        执行指令:apt-get install nginx

        

/* nginx 指令 */

// 启动服务
1.service nginx start
2.systemctl start nginx.service

// 重启服务
systemctl restart nginx.service

// 重新加载 ngxin 配置文件
nginx [*.conf] -s reload

// 查看ngxin服务状态
systemctl status nginx.service

// 查看所有服务
systemctl list-units --type=service



安装mysql 

        执行指令:apt-get install mysql-server

/* 安装完成 */
执行指令: mysql_secure_installation

#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)

#2
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)

#3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y (我的选项)

#4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)

#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)

#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)


// 检查 mysql 服务状态
systemctl status mysql.service

// 配置远程访问
mysql -uroot -p
// 切换 mysql 数据库
use mysql
// 更新访问地址 localhost -> %   [localhost代表本地访问,%代表所有主机,也可以指定ip]
update user set host='%' where user='root';
// 刷新权限 
flush privileges;

-------------------------------------------------------------------
// 查看所有数据库
show databases;

// 查看用户权限; host字段 localhost代表本地访问,%代表所有主机,也可以指定ip
select host,user from mysql.user;

// 切换数据库
use [数据库名称]

// 重启数据库
service mysql restart

// 执行指令. 其中  root@localhost  :
GRANT ALL PRIVILEGES ON *.* TO root@% IDENTIFIED BY "密码";
//mysql8.0的话用这个
create user 'root'@'localhost' identified by '123456';
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

// 远程无法访问
去 /etc/mysql/mysql.conf.d/mysqld.cnf  查看bind-addredd 字段并注释 
alter user 'root'@'%' identified with mysql_native_password by 'root';



关闭防火墙

        查看防火墙状态: ufw status (active开启,incative关闭)

        关闭防火墙:ufw disable

        打开防火墙:ufw enable

查看端口占用

        执行指令:netstat -tln

添加用户

        

// 添加用户   -m 生成用户目录
useradd [username] -m

// 设置用户登录密码
passwd [username]

// 为该用户指定命令解释程序(通常为/bin/bash)
usermod -s /bin/bash  [username]

// 为改用户指定用户主目录
usermod -d /home/[username] [username]

// 查看用户的属性
cat /etc/passwd

// 切换用户
su [username]

// 删除用户
userdel [username]


-------------------图形创建使用 adduser 指令
// 添加用户
adduser [username]

// 删除用户
deluser [username]


/* 
    给用户添加权限:
   
    切换到 root,输入visudo命令
  root@ubuntu:~# visudo
  该命令实际上打开的是/etc/sudoers文件,在“root ALL=(ALL:ALL) ALL”这一行下面加入一行:
  lin ALL=(ALL:ALL) ALL
  然后 ctrl + x 退出,是否保存选择yes,再按Enter键退出
--------------------------------------------------------------------
    查看用户组:

  cat /etc/group
  查看所有用户:

  cat /etc/shadow
  添加用户到用户组:

    例如添加 [用户名] 到 sudo 组

    $ sudo usermod -aG sudo [用户名]
  或者,使用 adduser 也能成功:

    $ sudo adduser [用户名] sudo
  从组移除用户:

    $ sudo gpasswd -d [用户名] sudo
  查看用户所在组:

    $ id [用户名]

--------------------------------------------------------------------


*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值