- CentOS7
- 服务器配置
/etc/ssh/sshd_config
AllowTcpForwarding yes X11Forwarding yes- 服务器安装
xorg-x11-xauth
yum install -y xorg-x11-xauth - 服务器配置
- 本地修改文件
/etc/ssh/ssh_config
ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes
- 登录
ssh -X root@ip
/etc/ssh/sshd_configAllowTcpForwarding yes X11Forwarding yesxorg-x11-xauthyum install -y xorg-x11-xauth/etc/ssh/ssh_configForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes
ssh -X root@ip
asbru-cm 是一个类似的 windows 上 xshell 的远程连接管理软件。
curl -s https://packagecloud.io/install/repositories/asbru-cm/asbru-cm/script.deb.sh | sudo bash
sudo apt-get install asbru-cm
/etc/ssh/sshd_config# Authentication 项下的PermitRootLogin prohibit-password 改成 PermitRootLogin yessudo systemctl restart sshd通常该文件位于 ~/.ssh/config ,权限必须是 644 。常见配置如下:
Host alias
User server
HostName remote_server.com
port 30022
IdentityFile ~/.ssh/id_rsa
接下来可以通过 ssh alias 来代替 ssh -p 30022 server@remote_server.com ,并免输密码(因为 IdentityFile )。
生成密钥对(若已生成则跳过)
ssh-keygen
复制到远程主机
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 user@remote_host
如果 ssh-copy-id 执行时出现 Permission denied :
/etc/ssh/sshd_config 设置 PasswordAuthentication yessudo systemctl restart sshssh-copy-id或仍然出现 Permission denied ,看一下远程主机 ~/.ssh/authorized_keys 文件权限,应该是 600 。
在使用 ssh 或 scp 时,通常使用 ssh -p 22 -i /path/to/pem user@hostname,如果主机名太长,或是 pem 文件太深,输入时很不方便,其实可以配置别名来简化输入。
编辑或创建文件 ~/.ssh/config,输入以下内容:
Host server
User user
HostName ipaddress_or_hostname
IdentityFile /path/to/pem
port 22
不需要的参数(例如 IdentityFile)可以不写,允许添加多个别名配置
使用方法:
# 登录到服务器
ssh server
# 复制文件
scp ~/file server:~/