sshd

server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
sudo apt-get install openssh-server
ps ef|grep ssh
sudo /etc/init.d/ssh start 或者 service sshd start
# 创建一个普通用户
useradd username
passwd username
vim /etc/ssh/sshd_config
Port 22333
PermitRootLogin no
TCPKeepAlive yes
ClientAliveInterval 360
ClientAliveCountMax 20
# 给普通用户附sudo权限
chmod u+w /etc/sudoers
vim /etc/sudoers
root ALL=(ALL) ALL
username ALL=(ALL) ALL
chmod u-w /etc/sudoers
/etc/init.d/ssh start
service sshd restart
firewall-cmd --permanent --add-port=22333/tcp
firewall-cmd --reload

client

1
ssh -p 22333 username@ip

SSH无密码登录

1
2
3
4
5
6
7
8
9
# client:生成SSH公钥
ssh-keygen -t rsa -C "邮箱"
# 将SSH公钥上传到Linux服务器
ssh-copy-id -p 22 username@remote-server
# 将client端的gedit ~/.ssh/id_rsa.pub的内容放到server端~/.ssh/authorized_keys
# 等同于如下
cat ~/.ssh/id_rsa.pub | ssh username@your_host \
"cat - >> /home/username/.ssh/authorized_keys"
Share Comments