0%

Termux(Android)配置

最近要接手一些运维的工作
有时候需要远程更新下
对比了几个安卓的ssh客户端,发现termux最好用了(可以很方便的将迁移sessions)(Termius也挺好的)

修改源

termux-change-repo

根目录地址

1
2
$ echo $PREFIX
/data/data/com.termux/files/usr

安装sshd服务

1
2
3
4
pkg install termux-services
pkg install openssh
sv-enable sshd
sv start sshd

默认端口 8022
现在就可以用ssh登录了,用sftp发送文件了

设置Termux软键盘

1
2
3
4
5
6
## ~/.termux/termux.properties
extra-keys = [ \
['|', '~', '/', '.', '-', '_', 'ENTER'], \
['ESC', 'TAB', 'HOME','UP','END','DEL', 'exit'], \
['CTRL','ALT','LEFT','DOWN','RIGHT', 'BKSP', 'KEYBOARD'] \
]

问题

参考文档

  1. https://mirrors.tuna.tsinghua.edu.cn/help/termux/
  2. https://wiki.termux.com/wiki/Termux-services
  3. https://wiki.termux.com/wiki/Touch_Keyboard

附带自动生成的远程登录的脚本

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
eval "$(curl --silent https://www.mingilin.com/downloads/code/printcolor.sh)"
CACHE_DIR=~/.cache/
mkdir -p $CACHE_DIR
CFG_FILE=${CACHE_DIR}/ssh_test_cfg.cfg
if [ "$(uname -o)" == "Android" ];then
GREP="busybox grep"
else
GREP=grep
fi
MYSSH_KEY_DIR=~/myssh
cat > $CFG_FILE <<EOF
{"id":"7", "group":["","0. 内网机器"], "name":"DNS服务器-192.168.50.12", "user":"root", "host":"192.168.50.12", "port":"9022"}
{"id":"63", "group":["","Z101. vagrant"], "name":"192.168.56.10", "user":"root", "host":"192.168.56.10", "port":"22"}
{"id":"64", "group":["","Z101. vagrant"], "name":"192.168.56.11", "user":"root", "host":"192.168.56.11", "port":"22"}
EOF

function show_list() {
filter=$1
group=""
while read line_t; do
if [ "$filter" == "" ]; then
line=$line_t
else
line=$(echo $line_t | ${GREP} "$filter")
fi
if [ "$line" == "" ]; then
continue
fi
group1=$(echo $line | jq '.group | join("")')
port=$(echo $line | jq .port | sed 's/"//g')
if [ "$port" == "0" ]; then
continue
fi
if [ "$group" == "$group1" ]; then
echo -n " "
echo $line | jq '[.id,.name] | join(" ===> ")' | sed 's/"//g'
else
group=$group1
echo ""
print_info "======================================================="
_print_info ">>> "
print_info $(echo $line | jq -r '.group | .[1:] | join(" > ")')
print_info "-------------------------------------------------------"
echo -n " "
echo $line | jq -r '[.id,.name] | join(" ===> ")'
fi
done < $CFG_FILE
}

function login() {
id=$1
line=$(cat $CFG_FILE | ${GREP} "\"id\":\"$id\"")
sshhost=$(echo $line | jq -r .host)
sshport=$(echo $line | jq -r .port)
sshuser=$(echo $line | jq -r .user)
print_info "===> login $sshuser@$sshhost port:$sshport"
ssh -o GSSAPIAuthentication=no -o StrictHostKeyChecking=no -p $sshport $sshuser@$sshhost
}

function start_sshagent() {
[ ! -d $MYSSH_KEY_DIR ] && echo "[error] not found dir: $MYSSH_KEY_DIR" && exit

eval $(ssh-agent)
for i in $(find $MYSSH_KEY_DIR -type f); do
ssh-add -q $i
done
ssh-add -l
}

function stop_sshagent() {
eval $(ssh-agent -k)
}

function help() {
print_info "======================================="
print_info "show_list - list all sessions "
print_info "show_list group - list group sessions"
print_info "login id - login"
print_info "======================================="
}

case $1 in
"login")
start_sshagent
login $2
stop_sshagent
;;
"show_list")
show_list $2
;;
*)
help
;;
esac