作者: 方舟笔记
Linux服务器采用密钥认证登录
Linux(Red Hat Enterprise Linux (RHEL), CentOS and Scientific Linux (SL), Oracle Linux (OL).)
第一种 在客户端生成密钥对,并将公钥上传到服务器端
一、客户端操作:
#ssh-keygen -t rsa -b 2048 //生成公钥和私钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): //可输入私钥保护密码
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
#scp -P 22 .ssh/id_rsa.pub root@122.112.84.50: //将公钥上传到服务器的username目录
二、服务器端操作:(需要被连接的)
使用username登录
#mkdir -p .ssh
#chmod 700 .ssh
#cat .ssh/id_rsa.pub>>.ssh/authorized_keys
#chmod 600 .ssh/authorized_keys
#ssh root@122.112.84.50 //客户端登录服务端
--------------------
第二种 使用PUTTY或Xshell或SecureCRT生成密钥对
1:使用username登录
#mkdir -p .ssh
#chmod 700 .ssh
2:使用puttygen生成公钥和私钥,将公钥上传到服务器端username的.ssh目录下
3:#cat .ssh/id_rsa.pub>>.ssh/authorized_keys
#chmod 600 .ssh/authorized_keys
3:用putty私钥登陆出现server refused our key //打开sshd_config找到StrictModes yes修改为StrictModes no
#/etc/init.d/sshd reload 重新加载下即可 //修改验证文件,不推荐
--------------------
第三种 在服务器端生成密钥对,把私钥下载下来使用
1:在目标服务器生成公钥和私钥对(这里以root,也可以使用其他username)
#ssh-keygen -t rsa -b 2048 //生成公钥和私钥
#ssh-keygen -t rsa -b 4096
#ssh-keygen -t rsa -b 16384 //key bits exceeds maximum 16384
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): //可输入私钥保护密码
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
2:#chmod 700 .ssh
#cat .ssh/id_rsa.pub>>.ssh/authorized_keys
#chmod 600 .ssh/authorized_keys
3:下载id_rsa(私钥)文件,使用puttygen保存为PUTTY能识别的文件(*.ppk),(Xshell 能直接使用id_rsa文件)登录服务器。
--------------------
第四种 已经生成好的公钥和私钥对
1:把公钥文件(id_rsa.pub)放到目标服务器/root/.ssh/中
2:#cat .ssh/id_rsa.pub>>.ssh/authorized_keys
chmod 600 .ssh/authorized_keys
3:把私钥文件(id_rsa)放到客户服务器/root/.ssh/中
chmod 600 ./ssh/id_rsa //否则提示 Permissions 0644 for '/root/.ssh/id_rsa' are too open.
//It is required that your private key files are NOT accessible by others.
//This private key will be ignored.
4:客户服务器登录目标服务器 ssh root@195.154.128.169 -p 4096
最后
修改服务器(或目标服务器)sshd服务配置只允许使用私钥文件登录 //先用密钥测试是否能正常登录服务器,然后再修改。
#vim /etc/ssh/sshd_config
将PasswordAuthentication yes 修改成 PasswordAuthentication no
重启sshd服务
Debian/Ubuntu执行/etc/init.d/ssh restart
CentOS执行:/etc/init.d/sshd restart
服务器拒绝接受我们的密钥 (server refused our key)
这样需要修改安全上下文的配置或者修改为正确的上下文
#getenforce (查看是否开启)
#vi /etc/sysconfig/selinux
SELINUX=enforcing
修改SELINUX=enforcing 为 SELINUX=disabled
#reboot //必须重启才生效
ls -Z 查看上下文
restorecon -R -v .ssh 恢复文件默认上下文
改变文件的上下文
chcon -R --reference=/etc/ssh/ssh_host_key.pub /root/.ssh/authorized_keys /root/.ssh/authorized_keys 参照文件/etc/ssh/ssh_host_key.pub 的上下文
安全上下文的错误信息日志
cat /var/log/audit/audit.log
type=AVC msg=audit(1467157590.251:90): avc: denied { read } for pid=1477 comm="sshd" name="authorized_keys" dev=sda3 ino=392460 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:admin_home_t:s0 tclass=file
完成
2015.9.18
VMware Workstation 11.1.1
修复内存分配问题:VMware Workstation 11.1.1
虚拟机软件VMware Workstation发布了11.1.1更新版本,本次更新修复了内存分配安全问题,建议使用该虚拟机软件的及时更新。
Workstation 11进行了优化以充分利用新的Haswell扩展,从而将CPU密集型操作的性能最多提高45%,例如,多媒体、加密/解密以及其他高强度性能测试。
- 更新的xHCI控制器
- 更新的NDIS驱动器
• 改进了Windows 8.1虚拟机的Unity。
• 最多为虚拟机分配2GB显存
• 改进了高DPI显示器
• 与VMware vCloud Air集成在一起
您现在可以连接到vCloud Air并从Workstation 11界面中上传、运行和查看虚拟机,从而在外部云中扩展您的虚拟机。
• 引导虚拟机并提供EFI支持
VMware-workstation-full-11.1.1-2771112
VMware Workstation 11.1.1 for Windows(64 位)
VMware Workstation 11.1.1 for Linux(64 位)
key
GA3MR-21E0P-089VZ-5QN5V-NVACA
YA118-61X1J-H892Z-EDZ5Z-PL8GA
YZ3WR-6XW86-484EY-2ZQ7V-YGACD
VZ7WR-60E1L-08D0P-VPWX9-NURT0
2015.06.10
Nginx配置https服务器,http重定向到https
Nginx配置https服务器,http重定向到https
server {
listen 443;
server_name www.zhangfangzhou.cn;
index index.html index.htm index.php default.html default.htm default.php;
root /home/zhangfangzhou.cn;
ssl on;
ssl_certificate /usr/local/nginx/conf/vhost/zhangfangzhou_cn.crt;
ssl_certificate_key /usr/local/nginx/conf/vhost/server.key;
include wordpress.conf;
error_page 404 /404.html;
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/zhangfangzhou.cn.log access;
error_log /home/wwwlogs/zhangfangzhou.cn.error.log error;
location /wp-content/uploads {
location ~ .*\.(php)?$ {
deny all;
}
}
#禁止附件目录运行PHP
#附件目录限制ip访问
location ^~ /wp-content/uploads/ {
deny 42.159.103.191;
}
#给 wp-login.php 添加 htpasswd 验证
location ^~ /wp-login.php {
location ~ [^/]\.php(/|$) {
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}
auth_basic "Please Input Your PassWord";
auth_basic_user_file /usr/local/nginx/conf/vhost/.htpasswd;
}
}
#重定向zhangfangzhou.cn到https://www.zhangfangzhou.cn
server {
listen 80;
server_name zhangfangzhou.cn;
return 301 https://www.zhangfangzhou.cn$request_uri;
}
#重定向www.zhangfangzhou.cn到https://www.zhangfangzhou.cn
server {
listen 80;
server_name www.zhangfangzhou.cn;
return 301 https://www.zhangfangzhou.cn$request_uri;
}
二进制和IP地址
二进制和IP地址
Binary and IP address
Binary Decimal
128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 0
61.135.169.125 十进制IP地址表示法
00111101100001111010100101111101 32位二进制IP地址表示法
1032300925 32位二进制换算成十进制
C:\>ping www.baidu.com
正在 Ping www.a.shifen.com [61.135.169.125] 具有 32 字节的数据:
来自 61.135.169.125 的回复: 字节=32 时间=84ms TTL=54
来自 61.135.169.125 的回复: 字节=32 时间=84ms TTL=54
来自 61.135.169.125 的回复: 字节=32 时间=84ms TTL=54
来自 61.135.169.125 的回复: 字节=32 时间=85ms TTL=54
61.135.169.125 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 84ms,最长 = 85ms,平均 = 84ms
C:\>ping 1032300925
正在 Ping 61.135.169.125 具有 32 字节的数据:
来自 61.135.169.125 的回复: 字节=32 时间=22ms TTL=56
来自 61.135.169.125 的回复: 字节=32 时间=85ms TTL=54
来自 61.135.169.125 的回复: 字节=32 时间=22ms TTL=56
来自 61.135.169.125 的回复: 字节=32 时间=84ms TTL=54
61.135.169.125 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 22ms,最长 = 85ms,平均 = 53ms
C:\>













































