ssh 免密码登陆

1. linux Server 运行下面命令:

ssh-keygen -t rsa -P ''

例如:

[root@vcentos .ssh]# ssh-keygen -t rsa -P ''
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
21:d8:b7:0c:1b:09:02:9b:50:b3:35:55:59:9a:31:bf root@vcentos.vlinux
The key's randomart image is:
+--[ RSA 2048]----+
|oo+ +...+o.      |
|.o = = ..*       |
|o . . * = .      |
|       B o .     |
|      . S E      |
|                 |
|                 |
|                 |
|                 |
+-----------------+

2. 在Server 上查看 .ssh/目录

[root@vcentos .ssh]# ll
total 16
-rw-------. 1 root root  402 Jul  8 10:03 authorized_keys
-rw-------. 1 root root 1675 Jul  8 10:04 id_rsa
-rw-r--r--. 1 root root  401 Jul  8 10:04 id_rsa.pub
-rw-r--r--. 1 root root  396 Jul  1 14:56 known_hosts

3. 将公钥id_rsa.pub,拷贝到client 上,并且把id_rsa.pub添加到客户机.ssh/authorzied_keys文件里

cat id_rsa.pub >> .ssh/authorized_keys

4.更改authorized_keys的权限为600

chmod 600 .ssh/authorized_keys

5. 然后尝试从client上登陆server

[root@vcentos ~]# ssh 192.168.95.22
The authenticity of host '192.168.95.22 (192.168.95.22)' can't be established.
ECDSA key fingerprint is 49:e8:67:50:33:0f:cc:2c:26:a3:aa:6b:7d:ed:24:59.
Are you sure you want to continue connecting (yes/no)? 

输入yes

只有第一次才需要进去确认。

ssh登陆centos服务器显示当前服务器磁盘容量

在linux服务器中,磁盘的容量状态不如windows那么直观显眼,除了做监控报警外,磁盘不够的时候很难及时知道

 

简单的修改下配置文件可以做到每次登陆服务器自动显示磁盘情况

 

[root@vcentos ~]# vim /root/.bash_profile

 

再结尾处添加

echo '=========================================================='
cat /etc/redhat-release
echo '=========================================================='
df -lh

然后保存后重新登陆ssh