【Termux】笔记


Termux

Termux 是一个适用于 Android 的终端模拟器,其环境类似于 Linux 环境。
无需Root 或设置即可使用。
Termux 会自动进行最小安装 - 使用 APT 包管理器即可获得其他软件包。

下载

Releases · termux/termux-app · GitHub


当前用户

获取当前用户名

whoami

需要 用户名 作为输入的命令,可以使用 $(whoami) 来代替
修改当前用户密码

passwd

安装国内软件源

安装清华源 1 2 ,或者安装其他的国内源 3

sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main stable main@' $PREFIX/etc/apt/sources.list

更新源

apt update && apt upgrade

远程ssh 4

多包一起安装:pkg install openssh termux-auth

安装必要组件,首先安装 身份认证的包

pkg install termux-auth

再安装个 openssh

pkg install openssh

需要执行 sshd 以启动 openssh,你也可以将sshd设置为 自启服务

sv-enable sshd 

不建议 echo "sshd" >> ~/.bashrc

(参考 Termux-services)


其他


Termux-services 5

以下的 <daemon> 代指服务名,需自行替换为

启动/关闭

# 启动
sv up <daemon>
# 关闭
sv down <daemon>

自启

sv-enable <daemon>

关闭自启

sv-disable <daemon>

查看日志

tail -f -n 100 $PREFIX/var/log/sv/<daemon>/current

自定义<Daemon>

mkdir -p $PREFIX/var/service/<daemon>/log
ln -sf $PREFIX/share/termux-services/svlogger $PREFIX/var/service/<daemon>/log/run
touch $PREFIX/var/service/<daemon>/run
vim $PREFIX/var/service/<daemon>/run

内容如下:

# <Daemon> service for termux
#!/data/data/com.termux/files/usr/bin/sh
exec <替换Daemon的执行命令> 2>&1
chmod +x $PREFIX/var/service/<daemon>/run

然后就可以操作了

sv-enable <daemon>

mysql 6

安装

pkg install mariadb

这段是笔记(忽略)

  • 启动mysql
nohup mariadb &
  • 备份
cd $PREFIX/var/lib/mysql
mkdir backup
cp ib_logfile* backup/
cd $PREFIX/etc
mkdir my.cnf.d
cp my.cnf my.cnf.bak

修改root密码 (这部分已经没用了,无法修改)

.../usr/etc $ mysql -u $(whoami)
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.9.2-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> set password for 'root'@'localhost' = password('123456');
Query OK, 0 rows affected (0.009 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.003 sec)

MariaDB [mysql]> quit;
Bye

初始化

$PREFIX/bin/mysql_secure_installation
.../usr/etc $ $PREFIX/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y
 <这里输入密码>

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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.

Remove anonymous users? [Y/n] y
 ... Success!

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? [Y/n] n
 ... skipping.

By default, MariaDB 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.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

设置mysql 自启

sv-enable mysqld

(参考 Termux-services)


  1. Termux换源 ↩︎

  2. Termux更换软件源(清华源) ↩︎

  3. Termux的安装、切换国内源 ↩︎

  4. 记录一次学习 Termux 踩坑 ↩︎

  5. Termux-services ↩︎

  6. 安卓手机termux上安装MariaDB数据库并实现公网环境下的远程连接 ↩︎

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值