一.ssh服务基本配置:
ssh端口:22
安装服务:openssh
服务端主程序:/usr/sbin/sshd
客户端主程序:/usr/bin/ssh
相关配置文件:
服务端配置文件:/etc/ssh/sshd_config
客户端配置文件:/etc/ssh/ssh_config
服务端配置文件:
基本设置部分
#Port 22 端口,默认22,建议服务器更改端口
#ListenAddress 0.0.0.0 默认监听所有IP
Protocol 2 协议版本2
#HostKey /etc/ssh/ssh_host_rsa_key 私钥存放位置
#HostKey /etc/ssh/ssh_host_dsa_key 私钥存放位置
#ServerKeyBits 1024 私钥位数
#SyslogFacility AUTH 日志记录ssh登录情况
SyslogFacility AUTHPRIV
#LogLevel INFO 日志等级
GSSAPIAuthentication yes 建议关闭,需要DNS验证
安全设定部分:
#LoginGraceTime 2m 登录时间
#MaxAuthTries 6 登录次数
#PermitRootLogin yes 允许root的ssh登录,建议关闭
#PubkeyAuthentication yes 是否允许使用公钥认证
#AuthorizedKeysFile .ssh/authorized_keys 公钥存放位置
#PermitEmptyPasswords no 不允许空密码登录
PasswordAuthentication yes 允许使用密码验证登录
二. ssh公钥认证:
(*yum install openssh)
第一步: 创建秘钥对
step1. ssh-keygen:
命令:ssh-keygen
Generating public/private rsa key pair.
-b:
Enter file in which to save the key (/root/.ssh/id_rsa):
----回车
-
f :
Created directory '/root/.ssh'.
-t
:
Enter passphrase (empty for no passphrase):
----回车
-q
:
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.
The key fingerprint is:
----回车
SHA256:GjboT/rTMPAUsdDhqma5YdIg3+Wx4+Rz4u+XKH9/aM0 root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]---+
| ..oo |
| oo. |
| o. |
| .o. |
|o o+* S |
|.+ = ++* |
|. X o B+ . . |
| = o B=.+ + o E |
| . .o*X+o o.. |
+----[SHA256]-----+
step2. 查看公钥对:
[root@localhost ~]# ls -a
. anaconda-ks.cfg .bash_profile .cshrc .tcshrc
.. .bash_logout .bashrc
.ssh
.viminfo
[root@localhost ~]# cd .ssh
[root@localhost .ssh]# ls
i
d_rsa id_rsa.pub
(---表示公钥对已生成
)
第二步: 上传公钥文件
step1. 上传:
step2. 输入密码:
root@172.16.84.129's password:
step3. 验证:
ssh 172.16.84.129 ip a
三.SSH子应用:
(一)SCP命令 -----
远程安全复制
格式1:scp user@host:file1 file2
格式2:scp file1 user@host:file2
方法1:scp ./file1 root@172.16.84.129
:
/
(表示在当前路径下把法file1传到地址为172.16.84.129客户端的根目录下)
|
注:1.当前文件与目的客户端之间有空格;
2.目的地与其下的路径之间有冒号;
方法2:scp root@172.16.84.128:/file1 ./桌面
(表示从客户端172.16.84.128的根目录下将file1文件复制到当前的桌面上)
(二)Sftp命令 -----安全FTP上传下载
格式:sftp
user@host
方法:
[root@localhost ~]#
sftp root@172.16.84.129
---目的地
Connected to 172.16.84.129.
sftp>
get ./file1
---命令和路径
Fetching /root/./file1 to file1
/root/./file1 100% 155 100.5KB/s 00:00
sftp>
ls file1
---查看
file1
sftp>
bye
[root@localhost ~]#
vi file1
---
打开文件