Skip to content

Instantly share code, notes, and snippets.

@tanhit243
Last active February 12, 2023 04:12
Show Gist options
  • Save tanhit243/5706c02cc1b9312f9c03fe3a70b4540a to your computer and use it in GitHub Desktop.
Save tanhit243/5706c02cc1b9312f9c03fe3a70b4540a to your computer and use it in GitHub Desktop.
ssh in my using ssh
:info_neon: Chuyên mục MIL - Monday I learn - 010
Chắc hẳn mọi người không còn lạ lẫm gì với cmd ssh đúng không ạ? Trong số này em xin giới thiệu về một số kinh nghiệm sử dụng trong công việc với ssh.
1. Luôn thiết lập tập tin config trong thư mục .ssh
Ưu điểm: Truy cập đến remote server một cách nhanh chóng mà không cần nhớ user, ip, port vv...
Lưu ý: Mỗi remote server sẽ tạo riêng một cặp key. Không dùng chung 1 cặp key duy nhất cho toàn bộ remote server.
Nếu bạn không may mắn để lộ private key và một vài thông tin khác thì có thể người có ý đồ xấu sẽ vào được toàn bộ các server khác.
Ví dụ: dev => abc_dev.key, stg => abc_stg
```
Host s-h-dev
Hostname 192.0.0.1
User vta
Port 22
IdentityFile ~/.ssh/s_dev_h
```
Thay vì ssh `vta@192.0.0.1 -i perm_file ...` thì chỉ cẩn `ssh s-h-dev` là đã có thể ssh lên remote server.
Ref: https://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
2. ssh thực thi các command trên remote server ngay trong terminal local một cách nhanh chóng
`ssh --option destination [command [argument ...]]`
Các công việc em đang áp dụng trong dự án:
1. Xem log trên dev: `ssh s-h-dev "tail -f ha/log/develop.log"`
2. Dump db trên dev: `ssh s-h-dev "docker exec p_database_dev /usr/bin/mysqldump -u root -p p_dev_fe | gzip -9" > p_dev_fe.sql.gz"`
Mọi người có thể dùng các cmd theo nhu cầu của mình nhé.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment