kali环境维护的一些命令

git拉取冲突

#删除本地修改,直接拉取最新
git reset --hard
git pull

docker容量满,清理镜像

docker system prune -a

docker停止删除所有容器和删除镜像

停止所有容器
删除所有容器
删除所有镜像
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker image rm $(docker image ls -q)

docker拉取超时,登录docker

#至官网注册docker账号并在终端登录docker(需先配置下方代理)
docker login --username=ddospolit
password:xxxx
sudo mkdir -p /etc/systemd/system/docker.service.d/ && \
sudo bash -c 'echo -e "[Service]\nEnvironment=\"HTTP_PROXY=http://192.168.136.1:8888/\"\nEnvironment=\"HTTPS_PROXY=http://192.168.136.1:8888/\"\nEnvironment=\"NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com\"" > /etc/systemd/system/docker.service.d/http-proxy.conf' && \
sudo systemctl daemon-reload && \
sudo systemctl restart docker
sudo systemctl show --property=Environment docker
sudo rm /etc/systemd/system/docker.service.d/http-proxy.conf
sudo systemctl daemon-reload
sudo systemctl restart docker

python多版本并存切换版本

(因kali经常更新,一些python包装在之前版本,python版本变动导致一些软件无法运行)

#检查kali目前已安装几个版本python,发现有v2、v3(9-11)
┌──(kali㉿kali)-[~/Desktop/Mobile-Security-Framework-MobSF]
└─$ python
Completing external command
python              python2.7-config    python3.9           python3.11-config   python3-futurize    python3-wsdump                                          
python2             python2-config      python3.10          python3-commonmark  python3-pasteurize  python-dotenv                                           
python2.7           python3             python3.11          python3-config      python3-qr          python-faraday 


#清除目前python、python2、python3配置

┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --remove python  /usr/bin/python3.9

┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --remove python2  /usr/bin/python2.7

┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --remove python3  /usr/bin/python3.10
                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --remove python3  /usr/bin/python3.11

或直接使用命令清除所有
update-alternatives --remove-all python
update-alternatives --remove-all python2
update-alternatives --remove-all python3

#验证是否移除python python2 python3配置
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --config python                    
update-alternatives: error: no alternatives for python
                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --config python2
update-alternatives: error: no alternatives for python2
                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --config python3
update-alternatives: error: no alternatives for python3


#配置python、python3可切换
添加python命令的3.9 
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1 
update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python (python) in auto mode
添加python命令的3.10 
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python python /usr/bin/python3.10 2
添加python命令的3.11
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python python /usr/bin/python3.11 3 
update-alternatives: using /usr/bin/python3.11 to provide /usr/bin/python (python) in auto mode



添加python3命令的3.9                                                                                                                                            
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python3 (python3) in auto mode

添加python3命令的3.10 

┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 3
update-alternatives: using /usr/bin/python3.10 to provide /usr/bin/python3 (python3) in auto mode

添加python3命令的3.11                                                                                                                                               
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 4
update-alternatives: using /usr/bin/python3.11 to provide /usr/bin/python3 (python3) in auto mode



#验证python命令和python3命令的版本配置,并配置为默认3.10

┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --config python 
There are 3 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                 Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.11   2         auto mode
* 1            /usr/bin/python3.10   1         manual mode
  2            /usr/bin/python3.11   2         manual mode
  3            /usr/bin/python3.9    1         manual mode

 
                                                                                                                                             
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --config python3
There are 3 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                 Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.11   4         auto mode
* 1            /usr/bin/python3.10   3         manual mode
  2            /usr/bin/python3.11   4         manual mode
  3            /usr/bin/python3.9    2         manual mode



#验证python命令和python3命令,此时所有命令均正常预期
                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# python 
Python 3.10.8 (main, Jan 16 2022, 17:12:18) 

                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# python3
Python 3.10.8 (main, Jan 16 2022, 17:12:18) 

                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# python2
Python 2.7.18 (default, Aug  1 2022, 06:23:55) 

debian更换kali源及GPD error错误

kali@kali:~$ grep -v '#' /etc/apt/sources.list | sort -u
deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware

kali@kali:~$

kali@kali:~$ echo deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware >/etc/apt/sources.list
kali@kali:~$ wget -q -O - https://archive.kali.org/archive-key.asc | apt-key add 

apt update提示”W: http://http.kali.org/kali/dists/kali-rolling/InRelease: Key is stored in legacy trusted”

rm -rf /var/lib/apt/lists
apt-get update
apt-get install kali-archive-keyring

使用update-alternatives切换python版本之后apt报错

apt update报错信息:ModuleNotFoundError: No module named ‘apt_pkg’

┌──(root㉿kali)-[/usr/lib/python3/dist-packages]
└─# cp apt_pkg.cpython-311-x86_64-linux-gnu.so apt_pkg.cpython-310-x86_64-linux-gnu.so

python3切换版本后pip版本未切换

curl https://bootstrap.pypa.io/get-pip.py | python3

使用 du 命令查看磁盘使用情况

du -h --max-depth=1
┌──(root㉿kali)-[/home/kali]
└─# cd ./.cache/

┌──(root㉿kali)-[/home/kali/.cache]
└─# du -h --max-depth=1
8.0K	./hashcat
8.0K	./pocl
3.9M	./fontconfig
8.0K	./dconf
4.0K	./obexd
17G	./vmware
148K	./RiseupVPN
16K	./sessions
4.0K	./doc
52K	./dirb
240M	./mozilla
448K	./samba
32K	./xfce4
4.0K	./gvfsd
4.0K	./mesa_shader_cache
4.0K	./gvfs
912M	./go-build
1.1M	./gstreamer-1.0
1.8M	./thumbnails
18G	.

rm -rf ./vmware
sudo timedatectl set-timezone Asia/Shanghai
[root@ccych72457obbe ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        3.9G     0  3.9G   0% /dev
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           3.9G  330M  3.5G   9% /run
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1        40G   36G  1.8G  96% /
tmpfs           781M     0  781M   0% /run/user/0

查看根目录占用大小
du -h --max-depth=1 /

查找大文件
find / -type f -size +500M

删除目录下所有某日志文件
rm -f svr.*

清除内容
> access.log
┌──(root㉿kali)-[/home/kali/Desktop]
└─# apt update 
Get:1 http://kali.download/kali kali-rolling InRelease [41.5 kB]
Err:1 http://kali.download/kali kali-rolling InRelease
  The following signatures were invalid: EXPKEYSIG ED444FF07D8D0BF6 Kali Linux Repository <[email protected]>
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
1153 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://kali.download/kali kali-rolling InRelease: The following signatures were invalid: EXPKEYSIG ED444FF07D8D0BF6 Kali Linux Repository <[email protected]>
W: Failed to fetch http://http.kali.org/kali/dists/kali-rolling/InRelease  The following signatures were invalid: EXPKEYSIG ED444FF07D8D0BF6 Kali Linux Repository <[email protected]>
W: Some index files failed to download. They have been ignored, or old ones used instead.

┌──(root㉿kali)-[/home/kali/Desktop]
└─# wget -q -O - https://archive.kali.org/archive-key.asc | apt-key add
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK