Skip to main content

13 posts tagged with "ubuntu"

View All Tags

腾讯云ubuntu使用root用户登录

· One min read

需求场景

腾讯开通的ubuntu主机,默认用户是ubuntu,并且这个ubuntu的权限还是相对比较低的,虽然提升了安全性,可是对于个人站长来说方便才是硬道理,自己也不会用root用户瞎操作。这个时候就需要用权限更大的root用户登录操作了。

步骤一:设置root密码

sudo passwd root回车设置两次密码即可

步骤二:修改ssh登录的配置

sudo vim /etc/ssh/sshd_config
找到文件的Authentication部分,将LoginGraceTime,PermitRootLogin,StrictModes前面的#号去掉。并且将PermitRootLogin的值改为yes

# Authentication:

LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

步骤三:重启ssh

sudo service ssh restart
重启之后就可以用root用户登录啦

ubuntu安装mysql/mariadb,开启远程登录

· 3 min read

步骤一:安装mysql

apt install mysql-server
#apt install mariadb-server

安装完成后验证是否安装成功

netstat -tap | grep mysql

步骤二:数据库初始化

mysql_secure_installation

根据提示选择y或n

Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
#要安装验证密码插件吗? 选择N
Please set the password for root here.
#输入要为root管理员设置的数据库密码
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. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
# 删除匿名账户 选择Y
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
# 禁止root管理员从远程登录 选择Y
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
# 删除test数据库并取消对它的访问权限 选择Y
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
# 刷新授权表,让初始化后的设定立即生效 选择Y

操作完成后检查mysql安装状态

systemctl status mysql

步骤三:重启mysql/mariadb

systemctl restart mysql
#systemctl restart mariadb

关于远程登录:

在步骤二中我们关闭了允许root用户远程登录,推荐创建一个本地的拥有所有权限的管理员账号,再使用Navicat的ssh隧道功能实现远程登录。

创建用于远程登录的管理员账户

sudo mysql;
use mysql;
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

ubuntu常用命令

· 2 min read

用户权限

#修改文件用户组
sudo chown -R pi:pi downloads/
sudo chown -R $(whoami) downloads/
#将用户添加到docker用户组,使用docker命令免输sudo
sudo usermod -aG docker $USER

端口

#查看开放端口
netstat -ltp
sudo lsof -i | grep -i listen
# 查看v2ray端口占用
sudo lsof -i | grep v2ray
# 查看80端口占用
sudo lsof -i:80

文件查找

# 递归查找并删除文件
find . -name "*.less" | xargs rm -rf

systemctl

#刷新配置
systemctl daemon-reload
#查看定时任务
systemctl list-timers
#查看开机启动项
systemctl list-unit-files --type=service | grep enabled
# 设置开机启动
systemctl enable v2ray
# 运行v2ray
systemctl start v2ray
# 重启v2ray
systemctl restart v2ray

解压缩

#解压tar包
tar -xvf file.tar
#解压tar.gz包
tar -zxvf file.tar.gz
#压缩tar.gz包
tar -zcvf file.tar.gz dir/
#解压tar.xz包
tar -xvJf node-v8.11.1-linux-x64.tar.xz

其他

#查看service启动日志
journalctl -u nginx.service -f
#查看应用日志文件
tail -f /var/log/nginx/error.log
#查看磁盘容量
df -h
#查看目录大小
du -sh *
#生成ssh公钥
ssh-keygen -t rsa
#设置别名
alias rm='rm -f'
#复制到剪切板
cat file.txt | pbcopy
# 查看防火墙当前状态
sudo ufw status
#查看系统时间
date -R
#设置时区
dpkg-reconfigure tzdata