[Up]常用資訊

[重點文章] 重點文章 [重點文章] 重點文章

2020年6月16日 星期二

[FreeBSD] FREEBSD_12 ssh登入時免輸入密碼

[FreeBSD] FREEBSD_12 ssh登入時免輸入密碼

 
#Step: 01 – FREEBSD_12 ssh登入時免輸入密碼
FreeBSD 12.1 ssh登入時免輸入密碼

自動程式需要進到別台機器時,沒辦法使用交談式方式輸入密碼,所以要預先交換好金鑰,這是傳統的作法[1]:

   1. 產生公私金錀
   2. 把公錀加到目標機器中帳號中的目錄下的 ~/.ssh/authorized_keys 中

後來發現 [網管心得]ssh keygen用法@外行中的外行提供一個方法,超級好用的,例如要登入192.168.1.1這台機器:

$ ssh-copy-id username@192.168.1.1

這是一台FREEBSD的機器,我如法泡製時,出現這樣的錯誤:

ssh-copy-id root@163.22.168.5:~
Could not open a connection to your authentication agent.
no keys found

嗯,它說你要有keys?

解決方法
一、建立 KEYS PAIR

$ ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <<按ENTER>>
Enter passphrase (empty for no passphrase):<<按ENTER>>
Enter same passphrase again:<<按ENTER>>
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ADHoATx9efwH5QSRNIIvRrL3ucT0Zjx9HwYqvRHJpJU root@myhost
The key's randomart image is:
+---[RSA 2048]----+
|o...+.+..==o.    |
| ooo B o.o+E     |
| ...= + . *..    |
|  .. + + o = .   |
|    o = S + o .  |
|       = B = . o |
|      . + o + o .|
|       .   .   . |
|                 |
+----[SHA256]-----+

於是乎,在家目錄下的隱藏目錄會出現兩個檔案,因為我是 root:

  id_rsa
  id_rsa.pub
  
二、把公鑰複製到遠端機器
$ ssh-copy-id -i ~/.ssh/id_rsa.pub  root@192.168.1.1
Password for root@servername: <<打入密碼>>
這樣就完成了,試著登入看看

$ ssh 192.168.1.1

成功連線不用再打密碼了

Freebsd MIB 檔案位置
/usr/local/share/snmp/mibs

切換 sh 
chsh -s csh


https://www.cyberciti.biz/faq/howto-install-vim-text-editor-under-freebsd/

set nocompatible
" Use Vim settings, rather than Vi settings
set softtabstop=2
" Indent by 2 spaces when hitting tab
set shiftwidth=4
" Indent by 4 spaces when auto-indenting
set tabstop=4
" Show existing tab with 4 spaces width
syntax on
" Enable syntax highlighting
filetype indent plugin on
" Enable indenting for files
set autoindent
" Enable auto indenting
set number
" Enable line numbers
colorscheme desert
" Set nice looking colorscheme
set nobackup
" Disable backup files
set laststatus=2
"show status line
set statusline=%F%m%r%h%w%=(%{&ff}/%Y)\ (line\ %l\/%L,\ col\ %c)
set wildmenu
" Display command line's tab complete options as a menu.
call plug#begin('~/.vim/plugged')
Plug 'pearofducks/ansible-vim'
" install and use neomake linting
Plug 'neomake/neomake'
" install jedi auto for python
Plug 'davidhalter/jedi-vim'
" Install  PEP8 support
Plug 'Vimjas/vim-python-pep8-indent'
call plug#end()
colorscheme desert
" Get help 
nnoremap  H :execute "!pydoc3 " . expand("")
" Run code
autocmd FileType python nnoremap   :exec '!clear; python3' shellescape(@%, 1)
" Edit vimr configuration file
nnoremap ve :e $MYVIMRC
" " Reload vimr configuration file
nnoremap vw :source $MYVIMRC

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
   
https://github.com/junegunn/vim-plug


更新

更新 .vimrc
root@FreeBSD12-1-Default01:~ # cat .vimrc
set nocompatible
" Use Vim settings, rather than Vi settings
set softtabstop=2
" Indent by 2 spaces when hitting tab
set shiftwidth=4
" Indent by 4 spaces when auto-indenting
set tabstop=4
" Show existing tab with 4 spaces width
syntax on
" Enable syntax highlighting
filetype indent plugin on
" Enable indenting for files
set autoindent
" Enable auto indenting
set number
" Enable line numbers
colorscheme desert
" Set nice looking colorscheme
set nobackup
" Disable backup files
set laststatus=2
"show status line
set statusline=%F%m%r%h%w%=(%{&ff}/%Y)\ (line\ %l\/%L,\ col\ %c)
set wildmenu
"height ligth cusor
set bg=dark
set cursorline
set cursorcolumn
"
highlight CursorLine cterm=none ctermbg=236
highlight CursorColumn cterm=none ctermbg=236
" 显示tab和空格
set list
" 设置tab和空格样式
set lcs=tab:\|\ ,nbsp:%,trail:-
" 设定行首tab为灰色
highlight LeaderTab guifg=#666666
" 匹配行首tab
match LeaderTab /^\t/
" Display command line's tab complete options as a menu.
call plug#begin('~/.vim/plugged')
Plug 'pearofducks/ansible-vim'
" install and use neomake linting
Plug 'neomake/neomake'
" install jedi auto for python
Plug 'davidhalter/jedi-vim'
" Install  PEP8 support
Plug 'Vimjas/vim-python-pep8-indent'
call plug#end()
colorscheme desert
" Get help
nnoremap  H :execute "!pydoc3 " . expand("")
" Run code
autocmd FileType python nnoremap   :exec '!clear; python3' shellescape(@%, 1)
" Edit vimr configuration file
nnoremap ve :e $MYVIMRC
" " Reload vimr configuration file
nnoremap vw :source $MYVIMRC


###############################################################################
#                                  INPUTS                                     #
###############################################################################
[[inputs.snmp]]
  name_prefix = "exec6_"
  agents = [ "172.19.26.205" , "172.19.26.206" ]
  version = 2
  community = "public"
  interval = "60s"
  timeout = "10s"
  retries = 3
  name = "F5_system"

  [[inputs.snmp.field]]
    name = "hostname"
    oid = "RFC1213-MIB::sysName.0"
    is_tag = true
  [[inputs.snmp.field]]
    name = "uptime"
    oid = "1.3.6.1.4.1.3375.2.1.6.6.0"
  [[inputs.snmp.field]]
    name = "F5_httpRequests"
    oid = "1.3.6.1.4.1.3375.2.1.1.2.1.56.0"
  [[inputs.snmp.field]]
    name = "F5_client_connections"
    oid = "1.3.6.1.4.1.3375.2.1.1.2.1.8.0"
  [[inputs.snmp.field]]
    name = "F5_client_bytes_in"
    oid = "1.3.6.1.4.1.3375.2.1.1.2.1.60.0"
  [[inputs.snmp.field]]
    name = "F5_Total_Connections"
    oid = "1.3.6.1.4.1.3375.2.1.1.2.1.8.0"
  [[inputs.snmp.field]]
    name = "F5_New_Connects"
    oid = "1.3.6.1.4.1.3375.2.1.1.2.12.8.0"
  [[inputs.snmp.field]]
    name = "F5_New_Accepts"
    oid = "1.3.6.1.4.1.3375.2.1.1.2.12.6.0"

 [[inputs.snmp.field]]
    name = "F5_Synchronization_status_color"
    oid =  "F5-BIGIP-SYSTEM-MIB::sysCmSyncStatusColor.0"

 [[inputs.snmp.table]]
    name = "F5_CPU"
    oid = "F5-BIGIP-SYSTEM-MIB::sysMultiHostCpuTable"
    inherit_tags = [ "hostname" ]

 [[inputs.snmp.table]]
    name = "F5_Memory_Usage"
    oid = "F5-BIGIP-SYSTEM-MIB::sysMultiHostTable"
    inherit_tags = [ "hostname" ]

###############################################################################
#                                  OUTPUTS                                    #
###############################################################################
[outputs.influxdb]
    namepass = ["exec6_*"]
    urls = ["http://127.0.0.1:8086"]
    precision = "s"
    timeout = "5s"
    retention_policy = ""
    database = "exec6_telegraf"
    username = "exec6_tel"
    password = "password"

沒有留言:

張貼留言