Linux随手写
1.查看本机出口的公网IP以及某个IP归属地
[root@centos ~]# curl cip.cc IP : 113.118.x.x 地址 : 中国 广东 深圳 运营商 : 电信 数据二 : 广东省深圳市 | 电信 数据三 : 中国广东深圳 | 电信 URL : http://www.cip.cc/113.118.x.
[root@centos~]# curl cip.cc/114.114.114.114
IP : 114.114.114.114
地址 : 114DNS.COM 114DNS.COM
数据二 : 江苏省南京市 | 南京信风网络科技有限公司GreatbitDNS服务器
数据三 : 中国江苏南京
URL : http://www.cip.cc/114.114.114.114
2.查看本机日期时间
[root@centos ~]# date 2021年 08月 17日 星期二 16:25:04 CST
3.查看日期
[root@centos ~]# cal 八月 2021 日 一 二 三 四 五 六 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
4.查看内存信息
[root@centos ~]# free -h total used free shared buff/cache available Mem: 1.8G 357M 1.2G 9.6M 223M 1.3G Swap: 2.0G 0B 2.0G
#解释:Mem 物理内存统计信息
total: #物理内存总量
used: #以使用的内存总量
free: #空闲内存总量
shared: #共享内存总量
buff/cache: #块设备与普通文件占用的缓存数量
available: #还可以被应用程序使用的物理内存大小
#解释:Swap 内存交换空间,当物理内存不足时,可以使用硬盘空间充当内存使用
total: #交换分区内存总量
used: #正在使用的交换分区内存
free: #空闲交换分区内存
5.查看分区情况
[root@centos ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 devtmpfs 898M 0 898M 0% /dev tmpfs 910M 0 910M 0% /dev/shm tmpfs 910M 9.7M 901M 2% /run tmpfs 910M 0 910M 0% /sys/fs/cgroup /dev/mapper/centos-root 27G 5.1G 22G 19% / /dev/sda1 1014M 150M 865M 15% /boot tmpfs 182M 0 182M 0% /run/user/0 tmpfs 182M 0 182M 0% /run/user/1000
6.windows和linux互传文件其一的方法
1.sftp登录
C:\Users\Administrator> sftp root@111.231.x.x root@111.231.x.x's password: Connected to 111.231.x.x.
2.指定文件传输
sftp> put C:\Users\Administrator\Desktop\机密表格.xlsx /root/ Uploading C:/Users/Administrator/Desktop/机密表格.xlsx to /root/机密表格.xlsx C:/Users/Administrator/Desktop/机密表格.xlsx 100% 9800 290.7KB/s 00:00 sftp>
3.验证结果
C:\Users\Administrator> ssh root@111.231.x.x root@111.231.16.165's password: Last login: Wed Aug 25 11:29:09 2021 from 119.123.x.x [root@VM-centos ~]# ls 机密表格.xlsx 将Linux的文件下载到Windows桌面上
1.sftp登录
C:\Users\Administrator> sftp root@111.231.x.x root@111.231.16.165's password: Connected to 111.231.x.x.
2.是用get将linux目录下某个文件上传到win下
sftp> get /root/机密表格.xlsx C:/Users/Administrator/Desktop/
Fetching /root/机密表格.xlsx to C:/Users/Administrator/Desktop/机密表格.xlsx
/root/机密表格.xlsx 100% 9800 149.9KB/s 00:00
7.查看端口占用(netstat)
[root@VM-centos ~]# netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:10086 0.0.0.0:* LISTEN 11350/nginx: master tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11350/nginx: master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1261/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1440/master tcp6 0 0 :::3306 :::* LISTEN 18169/mysqld tcp6 0 0 :::80 :::* LISTEN 11350/nginx: master tcp6 0 0 :::21 :::* LISTEN 1052/vsftpd tcp6 0 0 :::22 :::* LISTEN 1261/sshd tcp6 0 0 ::1:25 :::* LISTEN 1440/master udp 0 0 0.0.0.0:68 0.0.0.0:* 977/dhclient udp 0 0 172.17.0.15:123 0.0.0.0:* 581/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 581/ntpd udp6 0 0 fe80::5054:ff:fedb::123 :::* 581/ntpd udp6 0 0 ::1:123 :::* 581/ntpd
注释解释:
-t (tcp) 仅显示tcp相关选项
-u (udp)仅显示udp相关选项
-n 拒绝显示别名,能显示数字的全部转化为数字
-l 仅列出在Listen(监听)的服务状态
-p 显示建立相关链接的程序名
8.设置登陆机制,防止密码破解
1.ssh登录方式限制
vi /etc/pam.d/sshd auth required pam_tally2.so deny=3 unlock_time=300 even_deny_root root_unlock_time=300
###auth required 认证
###pam_tally2.so 使用该模块实现认证机制
###deny=3 登录次数
###unlock_time=300 普通用户锁定后解锁时间
###even_deny_root root用户一样受限制
###root_unlock_time=300 root用户锁定后解锁时间
9.关掉swap分区
(1)临时关闭swap分区, 重启失效;
swapoff -a
(2)永久关闭swap分区
sed -ri 's/.*swap.*/#&/' /etc/fstab