常用命令及小技巧等
[root@host ~]# ps -ef | grep ssh
root 1561 1 0 02:57 ? 00:00:00 /usr/sbin/sshd
root 1750 1561 0 02:58 ? 00:00:00 sshd: root@pts/0
root 1779 1561 0 02:59 ? 00:00:00 sshd: [accepted]
root 1788 1754 0 03:00 pts/0 00:00:00 grep ssh
查看进程ssh
[root@host ~]# netstat -lntup | grep 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1561/sshd
tcp 0 0 :::22 :::* LISTEN 1561/sshd
查看端口号22
[root@host ~]#/etc/init.d/iptables stop
iptables: Settingchains to policy ACCEPT: filter [ OK ]
iptables: Flushingfirewall rules: [ OK ]
iptables:Unloading modules: [ OK ]
闭关防火墙 status查看状态
如ssh故障,如何排查
服务端叫ssh服务,进程名sshd,软件openssh连接用 openssl加密用
正常我们添加用户
useradd xxx
然后passwd YYYYY密码
这属于交互式的
[root@host ~]#echo "021241" | passwd --stdin xxx(用户名)
Changing passwordfor user user1.
passwd: allauthentication tokens updated successfully. 也可以这样,非交互式设置密码
SELinux 正常生产环境关闭的
查看目前状态
[root@hosttmp" "21:23:04]#getenforce
Enforcing
修改 vim/etc/selinux/config 或者 用sed
[root@hosttmp" "21:15:38]#sed 's#SELINUX=enforcing#SELINUX=disabled#g'/etc/selinux/config
差点就错了 没用加-i 只是显示的时候替换 实际并没有修改源文件
#sed -i's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
这样就好了
不过这样 也行 先看 对了 再改
得重启再能生效
如果不想重启
[root@hosttmp" "21:27:47]#setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@hosttmp" "21:28:31]#setenforce 0
查看运行级别 cat /etc/inittab
# Defaultrunlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this) 关机
# 1 - Single user mode 单用户状态
# 2 - Multiuser, without NFS (The same as 3,if you do not have networking) 多用户 没用NFS
# 3 - Full multiuser mode 命令行模式 正在使用
# 4 - unused 保留
# 5 - X11 桌面
# 6 - reboot (Do NOT set initdefault to this) 重启
id:3:initdefault: 在这里可以修改
查看当前运行级别
[root@hosttmp" "21:36:13]#runlevel
N 3
其实# init 6就是重启 #init 0 就是关机
shutdown -h now
shutdown -r now
这两命令我不习惯用了
关闭防火墙
[root@hosttmp" "21:44:14]#/etc/init.d/iptables stop
iptables: Settingchains to policy ACCEPT: filter [ OK ]
iptables: Flushingfirewall rules: [ OK ]
iptables:Unloading modules: [ OK ]
[root@hosttmp" "21:52:24]#/etc/init.d/iptables status
iptables: Firewallis not running.
#chkconfigiptables off 永久关闭
[root@hosttmp" "22:28:17]#cp /etc/sysconfig/i18n /etc/sysconfig/i18n.old 备份
[root@hosttmp" "22:28:33]#echo 'LANG="zh_CN.UTF-8"' >/etc/sysconfig/i18n 重定向内容
[root@hosttmp" "22:29:16]#source /etc/sysconfig/i18n 重读
[root@hosttmp" "22:29:26]#echo $LANG
zh_CN.UTF-8
改为中文字符集
再改回来
[root@hosttmp" "22:33:30]#rm -f /etc/sysconfig/i18n
[root@hosttmp" "22:33:38]#mv /etc/sysconfig/i18n.old /etc/sysconfig/i18n
[root@hosttmp" "22:33:54]#source /etc/sysconfig/i18n
[root@hosttmp" "22:34:03]#echo $LANG
en_US.UTF-8
history -c 删除全部命令历史
history -d X 删除指定命令
echo $TMOUT
export TMOUT=3600 类似锁屏
export HISTSIZE=5 保留5条命令行记录
exportHISTFILESIZE=5 保留命令历史文件记录的长度
以上只是当前生效
要想永久 可以放这个文件里
[root@host ~""22:55:02]#cat /etc/profile
然后source下生效
issue 说是启动时有显示 不安全 要删除(清空)????????
有时候 清空没问题 删除就有
快照类似 在虚拟机上面N个节点
克隆类似 电影复制到别的电脑上
但是我克隆完,用新的不能上网
解决方法:
1:编辑/etc/sysconfig/network-scripts/ifcfg-eth0配置文件,将ifcfg-eth0的配置文件里里面以前的关于MAC地址这一行删除掉或修改。 UUID不删也能用
2:找到/etc/udev/rules.d/70-persistent-net.rules删除后重启机器,系统会自动生成一个70-persistent-net.rules文件。
[root@host ~""00:40:45]#mount /dev/sr0/mnt
mount: blockdevice /dev/sr0 is write-protected, mounting read-only
[root@host ~""00:40:55]#mount 这个版本已不是/dev/cdrom 而是/dev/sr0
/dev/sr0 on /mnttype iso9660 (ro)
cat/etc/fstab 系统自动已经挂载的
bin 常用二进制命令 比如cp ls mkdir rm cut
boot 内核及系统引导程序所需的文件目录
data
dev 设备文件目录
etc 二进制软件安装包(yum,rpm)的配置文件默认路径
fstab 开机自动挂载设备的文件
inittab 开机自动加载的文件
motd 登录显示自定义信息
profile 全局环境变量
home 普通用户家目录
lib 库
lib64
lost+found
media
mnt
opt
proc 显示内核及进程信息的虚拟文件系统
root 超级管理员的家目录
sbin和/usr/sbin 超级用户命令的目录
selinux
srv
sys
tmp 临时文件目录
usr 用户程序及数据、帮助文件、二进制命令等目录
var 变化的目录,一般是日志文件,cache的目录
service networkrestart 对所有网卡有效
ifdown eth0&& ifup eth0 只针对一个网卡
转载于:https://blog.51cto.com/11755576/1974765