1. 程式人生 > >linux服務ssh詳解

linux服務ssh詳解

ssh服務

ssh服務:

管理服務器的方式:

本地管理 (安裝系統、故障修復)

SSH遠程連接的方式

Linux: ssh命令

Windows:

Xshell; Xmanager

SecureCRT

Putty


提供ssh服務/ssh客戶端工具的軟件:


[[email protected] ~]# rpm -qa | grep ssh

openssh-server-6.6.1p1-33.el7_3.x86_64

openssh-clients-6.6.1p1-33.el7_3.x86_64


[[email protected] ~]# systemctl status sshd ------>查狀態


[[email protected] ~]# ss -antp | grep sshd

LISTEN 0 128 *:22 *:* users:(("sshd",pid=1202,fd=3))


1、遠程連接主機


# ssh [user@]host

# ssh 192.168.87.10

# ssh [email protected]

2、遠程連接主機執行命令


# ssh 192.168.87.10 ‘hostname‘


[[email protected]

/* */ ~]# ssh [email protected] ‘hostname‘




3、遠程復制文件的工具


scp, rsync (增量復制)


[[email protected] ~]# scp /etc/fstab 192.168.122.121:/tmp/


[[email protected] ~]# scp 192.168.122.121:/etc/passwd /tmp/


-r:復制目錄


rsync


[[email protected] ~]# rsync -av /bj/ 192.168.122.121:/sh


[[email protected]

/* */ ~]# rsync -av /bj 192.168.122.121:/sh



配置文件:/etc/ssh/sshd_config


1) 關閉SSH對主機名的解析


GSSAPIAuthentication no

UseDNS no


[[email protected] ~]# systemctl restart sshd



2) 禁用root用戶遠程連接


PermitRootLogin no


3) 修改默認的SSH端口


Port 22345

ListenAddress 192.168.122.121


[[email protected] ~]# ssh [email protected] -p 22345



關閉SELinux和防火墻


# setenforce 0

# vim /etc/sysconfig/selinux


關閉防火墻


# systemctl stop firewalld

# systemctl disable firewalld


SSH認證方式:


基於用戶名、密碼;默認

基於密鑰

基於密鑰的配置方法:

1、在客戶端生成密鑰對

2、把公鑰傳送給服務器



1) 在客戶端生成密鑰對

[[email protected] ~]# ssh-keygen -t rsa


[[email protected] ~]# ls .ssh/

id_rsa id_rsa.pub known_hosts


id_rsa 私鑰

id_rsa.pub 公鑰



2) 把公鑰傳送給服務器


[[email protected] ~]# ssh-copy-id -i -p 22345 192.168.87.10


本文出自 “lyw666” 博客,請務必保留此出處http://lyw666.blog.51cto.com/12823216/1957475

linux服務ssh詳解