PuTTY是一款开源免费的Telnet、SSH客户端工具,可用于远程管理、实时监控Linux服务器。
PuTTY的下载链接:https://pan.baidu.com/s/18r68o_KZcEMVrZHOi4dvpw 提取码:z8bd
错误:expected key exchange group packet from server
注释:只是一部分操作系统会出现这个错误。
重新打开PuTTY:
调整算法选择顺序:
保存会话:
会话保存成功:
选择会话,然后打开:
注释:只是第一次登录该服务器时,才会有这警告。
默认情况下,SSH登录是需要输入用户名、密码验证的
笺注:PuTTY无法保存用户名和密码。
解决中文乱码问题:
重新打开putty.exe,选择指定的会话后,点击“载入”
会话载入成功:
记得保存一下:
再次打开指定的会话:
笺注:回车键为复制字符串,鼠标右键为粘贴字符串。
WinSCP是常用的FTP、SFTP客户端软件,这里使用用户名、密码进行登录,文件协议为SFTP
选择指定的会话》登录:
注释:直接连到用户的家目录,上传和下载都没有问题的。
######
PuTTY使用SecureCRT创建的密钥对
目的:在服务器原来的公钥文件不用改的前提下,PuTTY也可以使用密钥对登录。
SecureCRT创建的密钥对可参考:SecureCRT+密钥对验证
运行 puttygen.exe
导入SecureCRT创建的密钥对:
注释:选择私钥文件。
注释:假如在SecureCRT创建的密钥对时没有创建通行短语,就没有这个步骤了。
密钥导入成功:(这里的公钥的内容与原来的已经不同了)
点击“保存私钥”
新的私钥文件:
笺注:不用管新的公钥内容,因为用旧的公钥文件内容即可。
#######
Linux服务端:
[root@centos8 ~]# useradd zhuohua
[root@centos8 ~]# echo '888' | passwd --stdin zhuohua
更改用户 zhuohua 的密码 。
passwd:所有的身份验证令牌已经成功更新。
给用户zhuohua生成一个文件夹:
[root@centos8 ~]# su - zhuohua
[zhuohua@centos8 ~]$ ssh 127.0.0.1
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:Zwe3TeKIW6szE3+SkP1c7gjJUUMTVaqteOERUNAkHk0.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '127.0.0.1' (ECDSA) to the list of known hosts.
zhuohua@127.0.0.1's password:
Last login: Sat Sep 12 16:51:05 2020
[zhuohua@centos8 ~]$ ls -alh
总用量 12K
drwx------ 3 zhuohua zhuohua 74 9月 12 16:51 .
drwxr-xr-x. 4 root root 35 9月 12 16:50 ..
-rw-r--r-- 1 zhuohua zhuohua 18 11月 9 2019 .bash_logout
-rw-r--r-- 1 zhuohua zhuohua 141 11月 9 2019 .bash_profile
-rw-r--r-- 1 zhuohua zhuohua 312 11月 9 2019 .bashrc
drwx------ 2 zhuohua zhuohua 25 9月 12 16:51 .ssh
将旧的公钥内容复制过来:(~/.ssh/authorized_keys 默认是不存在的)
[zhuohua@centos8 ~]$ vi ~/.ssh/authorized_keys
追加:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDig7LMG3m08fX/todhqAJS8qEKpxAhMz4WSxcQWtnH1M1nTZjh6LHN65oAl5yhAdnIlsGZq5C9DbwVLBH2sCADeR9fctPiZw+LyESBvZjUPiniyAErtPZD3Y/plFoLEBQOCROPUYT1/HednF8VQbpwmUcDhu1PhsOvUaLaDiyujw== jacky@jacky-PC
[zhuohua@centos8 ~]$ cat ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDig7LMG3m08fX/todhqAJS8qEKpxAhMz4WSxcQWtnH1M1nTZjh6LHN65oAl5yhAdnIlsGZq5C9DbwVLBH2sCADeR9fctPiZw+LyESBvZjUPiniyAErtPZD3Y/plFoLEBQOCROPUYT1/HednF8VQbpwmUcDhu1PhsOvUaLaDiyujw== jacky@jacky-PC
设置公钥文件的权限:
[zhuohua@centos8 ~]$ chmod 644 ~/.ssh/authorized_keys
[zhuohua@centos8 ~]$ ll ~/.ssh/authorized_keys
-rw-r--r-- 1 zhuohua zhuohua 226 9月 12 16:56 /home/zhuohua/.ssh/authorized_keys
[zhuohua@centos8 ~]$ cd .ssh/
[zhuohua@centos8 .ssh]$ pwd
/home/zhuohua/.ssh
[zhuohua@centos8 .ssh]$ ll
总用量 8
-rw-r--r-- 1 zhuohua zhuohua 228 9月 12 18:57 authorized_keys
-rw-r--r-- 1 zhuohua zhuohua 171 9月 12 16:51 known_hosts
登录验证方式:(也可以进入文件里修改,命令本身是有的;要切换到用户root才有权限进行操作)
// 禁止空密码用户远程登录
echo 'PermitEmptyPasswords no' >> /etc/ssh/sshd_config
// 启用密钥对验证
echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config
// 指定公钥库数据文件
echo 'AuthorizedKeysFile .ssh/authorized_keys' >> /etc/ssh/sshd_config
// 禁止root用户直接远程登录(可选)
echo 'PermitRootLogin no' >> /etc/ssh/sshd_config
// 禁用密码验证(可选)
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
重启sshd服务:
[root@centos8 ~]# systemctl restart sshd
PuTTY使用密钥对登录:
输入用户名zhuohua,再按回车键进行登录:(不用输入密码)
注释:
假如在SecureCRT创建的密钥对时没有创建通行短语,这里就不用输入通行短语;
用户zhuohua默认就可以切换为用户root,但要输入用户root的密码;
WinSCP也可以使用密钥对进行登录,文件协议为SFTP
注释:
假如在SecureCRT创建的密钥对时没有创建通行短语,这里就不用输入通行短语;
注释:直接连到用户的家目录,上传和下载都没有问题的。
CPU空闲率:
[root@centos8 ~]# vmstat -w
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
r b swpd free buff cache si so bi bo in cs us sy id wa st
3 0 0 936496 3220 413172 0 0 409 288 169 502 2 3 92 3 0
[root@centos8 ~]#
[root@centos8 ~]# vmstat -w |awk '{print $15}'|tail -1
92
CPU使用率:
[root@centos8 ~]# CPU_use_percent=$(expr 100 - $(vmstat -w |tail -1 |awk '{print $15}'))
[root@centos8 ~]# echo $CPU_use_percent
8
###
查看内存使用情况:(单位MB)
[root@centos8 ~]# free -m
total used free shared buff/cache available
Mem: 1800 481 912 26 406 1140
Swap: 4095 0 4095
可用内存量:( available )
[root@centos8 ~]# Mem_available=`free -m |head -2 |tail -1 |awk '{print $7}'`
[root@centos8 ~]# echo $Mem_available
1140
内存总量:
[root@centos8 ~]# Mem_total=`free -m |head -2 |tail -1 |awk '{print $2}'`
[root@centos8 ~]# echo $Mem_total
1800
内存已用量:
[root@centos8 ~]# Mem_used=$(expr $Mem_total - $Mem_available)
[root@centos8 ~]# echo $Mem_used
660
内存使用率:
[root@centos8 ~]# Mem_use_percent=$(expr $Mem_used \* 100 / $Mem_total)
[root@centos8 ~]# echo $Mem_use_percent
36
###
查看硬盘分区使用情况:
查看根分区的使用率:
[root@centos8 ~]# root_use_percent=$(df -hT |grep /$ |awk '{print $6}' |awk -F% '{print $1}')
[root@centos8 ~]# echo $root_use_percent
5
相关文章:
CentOS8基本命令
PuTTY远程管理Oracle Linux6.9
使用Shell脚本监控本机的CPU、内存、分区的使用率 |