kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

SELinux引起的SSH公钥认证失败

1
restorecon -r -vv /root/.ssh  

新装一台机器按照正常配置以后居然使用publickey方式认证不成功,但是使用密码认证是可以的。

具体现象表现为使用SecureCRT登陆时,出现如下出错提示: Public-key authentication with the server for user sw failed. Please verify username and public/private key pair. 查看服务器日志,找不到有用的相关记录。 之后直接在另一台机器上使用ssh连接,打开verbose模式(ssh -vvv),如下:

1
2
3
...
debug1: Next authentication method: password
sw@xxx.xxx.xxx.xxx's password:

可以看到,ssh先尝试了使用publickey进行认证,但是失败了,日志也没有显示相关原因,然后降级到使用密码认证。

求助万能的Google,发现serverfault上有一个案例的现象和出错信息与我遇到几乎一样,提问者怀疑是SELinux导致的。 案例 见 http://www.linuxidc.com/Linux/2013-07/87267p2.htm
下面的回复证实了确实是SELinux的问题,并且给出了解决方案:
Yes, SELinux is likely the cause. The .ssh dir is probably mislabeled. Look at /var/log/audit/audit.log. It should be labeled ssh_home_t. Check with ls -laZ. Run restorecon -r -vv /root/.ssh if need be.

Yep, SELinux was the cause: type=AVC msg=audit(1318597097.413:5447): avc:denied { read } for pid=19849 comm=“sshd” name=“authorized_keys” dev=dm-0 ino=262398 scontext=unconfined_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:admin_home_t:s0 tclass=file

It works after running “restorecon -r -vv /root/.ssh”. Thanks a lot.

我如获救命稻草,马上用ls -laZ检查了一下我的.ssh目录,果然不是ssh_home_t,心中窃喜,立刻使用restorecon对.ssh目录的context进行了恢复。

重新连接SSH,认证成功,问题解决

把SELinux暂时关了试试,使用setenforce 0把SELinux关闭,重新尝试连接,publickey认证正常了。
确认了是SELinux引发的问题
然后setenforce 1打开SELinux。

VirtualBox压缩vdi

http://blog.csdn.net/zcg1041bolg/article/details/7870170

VirtualBox guest os用久了vdi文件就会越来越大,就算在guest os中删除了一些文件,vdi也不会变小。

如果guest os 是windows:

  1. 先在guest os上运行磁盘碎片管理器,将各个磁盘的磁盘碎片减少;
  2. 下载sdelete (源地址http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx)
  3. 运行sdelete -c -z c:
  4. 关闭guest os 和 VirtualBox
  5. 在host os上运行VBoxManage modifyhd --compact yourImage.vdi

如果guest os 是Linux:

  1. 进入su
  2. dd if=/dev/zero of=test.file
  3. rm test.file
  4. 关闭guest os 和 VirtualBox
  5. 在host os上 运行 VBoxManage modifyhd --compact yourImage.vdi

这样在guest上看到占用的空间就和host上看到的空间就一样了。

CMD下 的命令行:

1
2
3
4
5
C:\Program Files>cd Oracle
C:\Program Files\Oracle>cd VirtualBox
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd --compact E:\ubuntu-virtualbox\ubuntu-virtualBox.vdi
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
C:\Program Files\Oracle\VirtualBox>

网卡声卡驱动

ubuntu10.04装在稍微新一点的机子时可能没有无线没有声音。

网卡驱动:

先把系统自带linux-firmware卸了,找一个比较新的装上
安装类似这种linux-backports-modules-compat-wireless-XXX-2.6.32-66-generic

声卡驱动1:安转旧点内核,然后。

1
2
3
sudo add-apt-repository ppa:ubuntu-audio-dev/ppa
sudo apt-get update
sudo apt-get install linux-alsa-driver-modules-$(uname -r)

现在支持最新的时2.6.32-34

声卡驱动2:声音不太正常

1.下载linux版本的官方驱动包

Realtek官网 http://www.realtek.com/downloads/ 点击右下方的 HD Audio Codec Driver
然后点击 I accept 神马的进入下一页 然后在最底下有linux版本的驱动,根据内核(一般都是2.6)版本下载驱动包

2.开始安装
1)解压源代码包
1
2
3
tar xfvj LinuxPkg_5.16rc25.tar.bz2  
cd realtek-linux-audiopack-5.16  
tar xfvj alsa-driver-1.0.24-5.16rc25.tar.bz2  
2)编译安装
1
2
3
4
5
6
7
sudo ./install  
/** 或:  
 *cd alsa-driver-1.0.24  
 *sudo ./configure --with-cards=hda-intel  
 *sudo make  
 *sudo make install  
 */
3)重启机器

sudo reboot