一、SSH服务建立远程连接
建立远程连接
ssh 主机号
-p 加端口号,默认连接是22端口
cat ~/.ssh/known_hosts #当第一次SSH连接的时候,本地产生的密钥文件
2、基于口令认证,也就是说每次连接都需要输入密码
3、基于密钥认证,也就是说不用输入密码就可建立连接
步骤:
ssh-keygen -t dsa #"dsa"也可替换成"rsa"
cd .ssh;ll
ssh-copt-id -i id_dsa.pub root@主机号
二、ssh服务常见配置
修改默认端口,重新建立连接
vim /etc/ssh/sshd_config
注!! 修改完端口后在重启ssh服务之前一定要检查一下selinux和firewalld一定要是关闭状态,否则ssh服务无法重启,主机连接不上。
1)selinux和firewalld关闭方法:
vim /etc/selinux/config #将原来的"enforcing"改为"disabled"
systemctl stop firewalld
systemctl restart sshd
禁止使用root用户连接
vim /etc/ssh/sshd_config #将pemitrootlogin中的"yes"改为”"no"
限制ssh监听的ip
vim /etc/ssh/sshd_config #添加本地内网IP
测试连接:
三、scp客户端附带的远程拷贝命令
scp /path/to/file root@主机号:/path/to/
scp root@主机号:/path/to/file /path/to/
-P(大写):接端口,默认22
-r:递归,表示拷贝目录
-p:表示在拷贝前后保持文件或目录属性
-l limit:限制速度